Skip to main content

token_transfer

Transfer tokens from the authenticated user to another user.

Method Signature

token_transfer: ActorMethod<[TransferRequest], TransferResponse>

Parameters

TransferRequest

FieldTypeRequiredDescription
tostringYesThe recipient’s address or principal
tokenidstringYesThe token identifier to transfer
amountTokenAmountYesAmount of tokens to transfer (bigint)

Response

TransferResponse

type TransferResponse = { ok: null } | { err: string }
  • Success: { ok: null } - Transfer completed successfully
  • Error: { err: string } - Error message describing what went wrong

Example Usage

const transferRequest = {
  to: "recipient-principal",
  tokenid: "token123",
  amount: 1000000000n // Token amount in smallest unit
};

const result = await actor.token_transfer(transferRequest);

if ('ok' in result) {
  console.log("Transfer successful");
} else {
  console.error("Transfer failed:", result.err);
}

Common Errors

  • Insufficient balance: Not enough tokens in sender’s account
  • Invalid recipient: Recipient address/principal is invalid
  • Token not found: Specified token ID doesn’t exist
  • Transfer blocked: Token transfers may be restricted
I