transfer static method

TransactionInstruction transfer({
  1. required Pubkey source,
  2. required Pubkey destination,
  3. required Pubkey owner,
  4. List<Pubkey> signers = const [],
  5. required bu64 amount,
})

Transfers tokens from one account to another either directly or via a delegate. If this account is associated with the native mint then equal amounts of SOL and Tokens will be transferred to the destination account.

Keys:

Single owner/delegate

  • [w] source - The source account.
  • [w] destination - The destination account.
  • [s] owner - The source account's owner/delegate.

Multisignature owner/delegate

  • [w] source - The source account.
  • [w] destination - The destination account.
  • [] owner - The source account's multisignature owner/delegate.
  • [s] signers - The signer accounts.

Data:

  • amount - The amount of tokens to transfer.

Implementation

static TransactionInstruction transfer({
  // Keys
  required final Pubkey source,
  required final Pubkey destination,
  required final Pubkey owner,
  final List<Pubkey> signers = const [],
  // Data
  required final bu64 amount,
}) {
  // * Single owner/delegate
  // 0. `[w]` The source account.
  // 1. `[w]` The destination account.
  // 2. `[s]` The source account's owner/delegate.
  //
  // * Multisignature owner/delegate
  // 0. `[w]` The source account.
  // 1. `[w]` The destination account.
  // 2. `[]` The source account's multisignature owner/delegate.
  // 3. ..3+M `[s]` M signer accounts.
  final List<AccountMeta> keys = [
    AccountMeta.writable(source),
    AccountMeta.writable(destination),
    AccountMeta(owner, isSigner: signers.isEmpty),
    for (final Pubkey signer in signers) AccountMeta.signer(signer),
  ];

  final List<Iterable<int>> data = [
    borsh.u64.encode(amount),
  ];

  return _instance.createTransactionIntruction(
    TokenInstruction.transfer,
    keys: keys,
    data: data,
  );
}