i get this error when i call functions from the Ledger Canister.
icp_balance : ()
Request ID: aa5c50026c4cb48ad219166dbb04543901e8c78e66a42ee351121b4fee8d679c
Reject code: 4
Reject text: Fail to decode argument 0 from table0 to record { account : vec nat8 }```
public shared ({ caller }) func icp_balance() : async ICP {
await ICPLedger.account_balance({
account = AccountIdentifier.fromPrincipal(caller, null);
})
};
AFAIK, youâre calling from an anonymous principal
Try using CLI
dfx canister call your_canister_name icp_balance
1 Like
Your function returns type âICPâ. make sure this type aligns with what the account_balance() function returns
1 Like
Hi, I would love to ask a question regarding this.
lets say the canister name is âcompâ, and comp has users(callers).
In my code, i call the transfer function from the ledger to transfer icp.
Once the frontend integrates the function and a user(caller) transfers the token, will it work??
Since the args doesnât take the from field.
or Will the ledger canister assume its the comp canister thats calling the function and not the caller??
How can I go about it??
Since we want users to be able to deposit their icp and withdraw anytime.
Thanks
public type TransferArg = {
to : Account;
fee : ?Nat;
memo : ?Blob;
from_subaccount : ?Blob;
created_at_time : ?Nat64;
amount : Nat;
};
There are two options: if you use transfer
or icrc1_transfer
, then whoever makes the call is the source identity. If the (logged in) frontend makes the call, the the userâs funds are used, if the backend makes the call then the backendâs funds are used. If you want the backend to transfer the userâs funds, you have to use icrc2_transfer_from
, which requires icrc2_approve
to happen before that.
2 Likes
ohh thanks this clarifies things
I get this error when i call the transfer func from the fronend.
Request ID: 8c32fdd3903bff9623d1dbcdbb3ee0f55d8f99746252cd807ecca23e5be3f994
Reject code: 5
Reject text: Canister ryjl3-tyaaa-aaaaa-aaaba-cai trapped explicitly: transaction is older than 86400 seconds```
FIxed it already, it has to do with the timestamp field, since Im in a different timezone, so i just made it null.