transferChecked static method
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 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.
Keys:
Single owner/delegate
[w]
source
- The source account.[]
mint
- The token mint.[w]
destination
- The destination account.[s]
owner
- The source account's owner/delegate.
Multisignature owner/delegate
[w]
source
- The source account.[]
mint
- The token mint.[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.decimals
- Expected number of base 10 digits to the right of the decimal place.
Implementation
static TransactionInstruction transferChecked({
// Keys
required final Pubkey source,
required final Pubkey mint,
required final Pubkey destination,
required final Pubkey owner,
final List<Pubkey> signers = const [],
// Data
required final bu64 amount,
required final u8 decimals,
}) {
// * Single owner/delegate
// 0. `[w]` The source account.
// 1. `[]` The token mint.
// 2. `[w]` The destination account.
// 3. `[s]` The source account's owner/delegate.
///
// * Multisignature owner/delegate
// 0. `[w]` The source account.
// 1. `[]` The token mint.
// 2. `[w]` The destination account.
// 3. `[]` The source account's multisignature owner/delegate.
// 4. `[s]` ..4+M, M signer accounts.
final List<AccountMeta> keys = [
AccountMeta.writable(source),
AccountMeta(mint),
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),
borsh.u8.encode(decimals),
];
return _instance.createTransactionIntruction(
TokenInstruction.transferChecked,
keys: keys,
data: data,
);
}