Hi,
I have a getBalance method as follows:
getBalance details
public shared ({ caller }) func getBalance() : async Text {
let account : AccountIdentifier = await IcpLedger.account_identifier({ owner = caller; subaccount = null});
let accountBalanceArgs : AccountBalanceArgs = { account };
let balance = await IcpLedger.account_balance(accountBalanceArgs);
return "Balance: " # Nat64.toText(balance.e8s);
};
Calling it from the terminal, I get
(“Balance: 10000000000”)
Then I have an initBalance method as follows:
initBalance details
public shared ({ caller }) func initBalance() : async Result.Result<IcpLedger.BlockIndex, Text> {
let me : AccountIdentifier = await IcpLedger.account_identifier({ owner = Principal.fromText("6qx4h-7o65n-z7e5h-m6pmk-yhkmp-isl3g-sv7xp-5eg2b-k7pib-g5iwv-3qe"); subaccount = null});
let meTransferArgs : IcpLedger.TransferArgs = {
memo = 1;
amount = {e8s = 1_000_000_000};
fee = {e8s = 10_000};
to = me;
from_subaccount = null;
created_at_time = null;
};
try {
let transferResult : IcpLedger.TransferResult = await IcpLedger.transfer(meTransferArgs);
switch (transferResult) {
case (#Err(e)) {
return #err("Couldn't transfer funds: " # debug_show (e));
};
case (#Ok(blockIndex)) {
return #ok(blockIndex)
};
};
} catch (error) {
return #err("Reject message: " # Error.message(error));
};
};
Basically it’s a simple transfer, but I get the following response:
(
variant {
err = “Couldn't transfer funds: #InsufficientFunds({balance = {e8s = 0}})”
},
)
How come??
Thanks