Skip to main content

token_withdraw

Withdraw tokens to external blockchain addresses using different protocols.

Method Signature

token_withdraw: ActorMethod<[WithdrawRequest], WithdrawResponse>

Parameters

WithdrawRequest

FieldTypeRequiredDescription
protocolWithdrawProtocolYesWithdrawal protocol to use
tokenidstringYesThe token identifier to withdraw
addressstringYesDestination address for the withdrawal
amountTokenAmountYesAmount of tokens to withdraw (bigint)

WithdrawProtocol

type WithdrawProtocol = { btc: null } | { ckbtc: null } | { volt: null }
Available protocols:
  • btc: Withdraw to Bitcoin network
  • ckbtc: Withdraw to Chain-key Bitcoin (ckBTC)
  • volt: Withdraw using Volt protocol

Response

WithdrawResponse

type WithdrawResponse = { ok: boolean } | { err: string }
  • Success: { ok: boolean } - Withdrawal initiated, boolean indicates status
  • Error: { err: string } - Error message describing what went wrong

Example Usage

Withdraw to Bitcoin

const withdrawRequest = {
  protocol: { btc: null },
  tokenid: "token123",
  address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", // Bitcoin address
  amount: 1000000000n // Token amount
};

const result = await actor.token_withdraw(withdrawRequest);

Withdraw using ckBTC

const withdrawRequest = {
  protocol: { ckbtc: null },
  tokenid: "token123", 
  address: "ckbtc-recipient-principal",
  amount: 500000000n
};

const result = await actor.token_withdraw(withdrawRequest);

Withdraw using Volt

const withdrawRequest = {
  protocol: { volt: null },
  tokenid: "token123",
  address: "volt-compatible-address",
  amount: 250000000n
};

const result = await actor.token_withdraw(withdrawRequest);

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

Common Errors

  • Insufficient balance: Not enough tokens for withdrawal
  • Invalid address: Destination address is invalid for the selected protocol
  • Protocol not supported: Token doesn’t support the selected withdrawal protocol
  • Minimum amount: Withdrawal amount below minimum threshold
  • Network congestion: Temporary network issues preventing withdrawal
I