Hey everyone,
I have a question about transferring ICP from one account to another. I’m using the import IcpLedger "canister:icp_ledger_canister";
statement. Before initiating the transfer, I call the ledger.icrc2_approve()
function. However, I encountered an error message:
Reject code: 4
Reject text: Anonymous principal cannot approve token transfers on the ledger.
Can anyone help me understand this issue?
here is the code:
let Ledger = actor “ryjl3-tyaaa-aaaaa-aaaba-cai” : LT.Self;
let icp_fee : Nat64 = 10_000;
public func transferICP( transferFrom : Principal, transferTo : [Nat8],transferAmount : Nat64) : async LT.TransferResult {
let res = await Ledger.icrc2_transfer_from({
memo: Nat64 = 0;
from_subaccount = ?Helpers.getSubaccount(transferFrom);
to = transferTo;
// The amount of ICP, minus the necessary transaction fee
amount = { e8s = transferAmount - icp_fee };
fee = { e8s = icp_fee };
created_at_time = ?{ timestamp_nanos = Nat64.fromNat(Int.abs(Time.now())) };
});
};