Complete ICP and ICRC token operations for Internet Computer Protocol applications
transfer(to, amount, options?)
to
: Recipient account (Principal, account ID string, or IAccount object)amount
: Amount to transfer (bigint in smallest token units)options
: Transfer options including memo, fee, subaccount, and timestampgetBalance(account?)
bigint
- Balance in smallest token units
getAccountId(principal?, subaccount?)
createAccount(principal, subaccount?)
generateSubaccount()
formatAmount(amount, decimals?)
parseAmount(amountStr, decimals?)
createMemo(input)
validateAccount(account)
Error Code | Description | Solution |
---|---|---|
INSUFFICIENT_BALANCE | Not enough tokens for transfer + fee | Check balance before transfer |
INVALID_ACCOUNT_ID | Invalid recipient address format | Validate address format |
INVALID_PRINCIPAL | Invalid principal format | Use Principal.fromText() |
TRANSFER_FAILED | Ledger rejected the transfer | Check amount, fee, and account validity |
LEDGER_UNAVAILABLE | Canister temporarily unavailable | Retry after some time |
BAD_FEE | Incorrect fee amount | Use the expected fee from metadata |
Promise.all()
for multiple balance checks