TokenInstruction.transferChecked constructor

TokenInstruction.transferChecked({
  1. required int amount,
  2. required int decimals,
  3. required Ed25519HDPublicKey source,
  4. required Ed25519HDPublicKey mint,
  5. required Ed25519HDPublicKey destination,
  6. required Ed25519HDPublicKey owner,
  7. List<Ed25519HDPublicKey> signers = const <Ed25519HDPublicKey>[],
})

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.

This instruction differs from TokenInstruction.transfer in that the token mint and decimals value is checked by the caller. This may be useful when creating transactions offline or within a hardware wallet.

Implementation

factory TokenInstruction.transferChecked({
  required int amount,
  required int decimals,
  required Ed25519HDPublicKey source,
  required Ed25519HDPublicKey mint,
  required Ed25519HDPublicKey destination,
  required Ed25519HDPublicKey owner,
  List<Ed25519HDPublicKey> signers = const <Ed25519HDPublicKey>[],
}) =>
    TokenInstruction._(
      accounts: [
        AccountMeta.writeable(pubKey: source, isSigner: false),
        AccountMeta.writeable(pubKey: mint, isSigner: false),
        AccountMeta.writeable(pubKey: destination, isSigner: false),
        AccountMeta.readonly(
          pubKey: owner,
          isSigner: signers.isEmpty,
        ),
        ...signers.map(
          (pubKey) => AccountMeta.readonly(pubKey: pubKey, isSigner: true),
        ),
      ],
      data: ByteArray.merge([
        TokenProgram.transferCheckedInstructionIndex,
        ByteArray.u64(amount),
        ByteArray.u8(decimals),
      ]),
    );