#[repr(C, u8)]pub enum TokenInstruction<'a> {
Show 28 variants
InitializeMint {
decimals: u8,
mint_authority: Pubkey,
freeze_authority: COption<Pubkey>,
},
InitializeAccount,
InitializeMultisig {
m: u8,
},
Transfer {
amount: u64,
},
Approve {
amount: u64,
},
Revoke,
SetAuthority {
authority_type: AuthorityType,
new_authority: COption<Pubkey>,
},
MintTo {
amount: u64,
},
Burn {
amount: u64,
},
CloseAccount,
FreezeAccount,
ThawAccount,
TransferChecked {
amount: u64,
decimals: u8,
},
ApproveChecked {
amount: u64,
decimals: u8,
},
MintToChecked {
amount: u64,
decimals: u8,
},
BurnChecked {
amount: u64,
decimals: u8,
},
InitializeAccount2 {
owner: Pubkey,
},
SyncNative,
InitializeAccount3 {
owner: Pubkey,
},
InitializeMultisig2 {
m: u8,
},
InitializeMint2 {
decimals: u8,
mint_authority: Pubkey,
freeze_authority: COption<Pubkey>,
},
GetAccountDataSize,
InitializeImmutableOwner,
AmountToUiAmount {
amount: u64,
},
UiAmountToAmount {
ui_amount: &'a str,
},
WithdrawExcessLamports = 38,
UnwrapLamports {
amount: COption<u64>,
},
Batch = 255,
}Expand description
Instructions supported by the token program.
Variants§
InitializeMint
Initializes a new mint and optionally deposits all the newly minted tokens in an account.
The InitializeMint instruction requires no signers and MUST be
included within the same Transaction as the system program’s
CreateAccount instruction that creates the account being initialized.
Otherwise another party can acquire ownership of the uninitialized
account.
Accounts expected by this instruction:
[writable]The mint to initialize.[]Rent sysvar
Fields
The authority/multisignature to mint tokens.
The freeze authority/multisignature of the mint.
InitializeAccount
Initializes a new account to hold tokens. If this account is associated with the native mint then the token balance of the initialized account will be equal to the amount of SOL in the account. If this account is associated with another mint, that mint must be initialized before this command can succeed.
The InitializeAccount instruction requires no signers and MUST be
included within the same Transaction as the system program’s
CreateAccount instruction that creates the account being initialized.
Otherwise another party can acquire ownership of the uninitialized
account.
Accounts expected by this instruction:
[writable]The account to initialize.[]The mint this account will be associated with.[]The new account’s owner/multisignature.[]Rent sysvar
InitializeMultisig
Initializes a multisignature account with N provided signers.
Multisignature accounts can used in place of any single owner/delegate accounts in any token instruction that require an owner/delegate to be present. The variant field represents the number of signers (M) required to validate this multisignature account.
The InitializeMultisig instruction requires no signers and MUST be
included within the same Transaction as the system program’s
CreateAccount instruction that creates the account being initialized.
Otherwise another party can acquire ownership of the uninitialized
account.
Accounts expected by this instruction:
[writable]The multisignature account to initialize.[]Rent sysvar- ..
2+N.[]The signer accounts, must equal to N where1 <= N <= 11.
Transfer
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.
Accounts expected by this instruction:
- Single owner/delegate
[writable]The source account.[writable]The destination account.[signer]The source account’s owner/delegate.
- Multisignature owner/delegate
[writable]The source account.[writable]The destination account.[]The source account’s multisignature owner/delegate.- ..
3+M[signer]M signer accounts.
Approve
Approves a delegate. A delegate is given the authority over tokens on behalf of the source account’s owner.
Accounts expected by this instruction:
- Single owner
[writable]The source account.[]The delegate.[signer]The source account owner.
- Multisignature owner
[writable]The source account.[]The delegate.[]The source account’s multisignature owner.- ..
3+M[signer]M signer accounts
Revoke
Revokes the delegate’s authority.
Accounts expected by this instruction:
- Single owner
[writable]The source account.[signer]The source account owner.
- Multisignature owner
[writable]The source account.[]The source account’s multisignature owner.- ..
2+M[signer]M signer accounts
SetAuthority
Sets a new authority of a mint or account.
Accounts expected by this instruction:
- Single authority
[writable]The mint or account to change the authority of.[signer]The current authority of the mint or account.
- Multisignature authority
[writable]The mint or account to change the authority of.[]The mint’s or account’s current multisignature authority.- ..
2+M[signer]M signer accounts
Fields
The type of authority to update.
The new authority
MintTo
Mints new tokens to an account. The native mint does not support minting.
Accounts expected by this instruction:
- Single authority
[writable]The mint.[writable]The account to mint tokens to.[signer]The mint’s minting authority.
- Multisignature authority
[writable]The mint.[writable]The account to mint tokens to.[]The mint’s multisignature mint-tokens authority.- ..
3+M[signer]M signer accounts.
Burn
Burns tokens by removing them from an account. Burn does not support
accounts associated with the native mint, use CloseAccount instead.
Accounts expected by this instruction:
- Single owner/delegate
[writable]The account to burn from.[writable]The token mint.[signer]The account’s owner/delegate.
- Multisignature owner/delegate
[writable]The account to burn from.[writable]The token mint.[]The account’s multisignature owner/delegate.- ..
3+M[signer]M signer accounts.
CloseAccount
Close an account by transferring all its SOL to the destination account. Non-native accounts may only be closed if its token amount is zero.
Accounts expected by this instruction:
- Single owner
[writable]The account to close.[writable]The destination account.[signer]The account’s owner.
- Multisignature owner
[writable]The account to close.[writable]The destination account.[]The account’s multisignature owner.- ..
3+M[signer]M signer accounts.
FreezeAccount
Freeze an Initialized account using the Mint’s freeze_authority (if
set).
Accounts expected by this instruction:
- Single owner
[writable]The account to freeze.[]The token mint.[signer]The mint freeze authority.
- Multisignature owner
[writable]The account to freeze.[]The token mint.[]The mint’s multisignature freeze authority.- ..
3+M[signer]M signer accounts.
ThawAccount
Thaw a Frozen account using the Mint’s freeze_authority (if set).
Accounts expected by this instruction:
- Single owner
[writable]The account to thaw.[]The token mint.[signer]The mint freeze authority.
- Multisignature owner
[writable]The account to thaw.[]The token mint.[]The mint’s multisignature freeze authority.- ..
3+M[signer]M signer accounts.
TransferChecked
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.
Accounts expected by this instruction:
- Single owner/delegate
[writable]The source account.[]The token mint.[writable]The destination account.[signer]The source account’s owner/delegate.
- Multisignature owner/delegate
[writable]The source account.[]The token mint.[writable]The destination account.[]The source account’s multisignature owner/delegate.- ..
4+M[signer]M signer accounts.
Fields
ApproveChecked
Approves a delegate. A delegate is given the authority over tokens on behalf of the source account’s owner.
This instruction differs from Approve 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.
Accounts expected by this instruction:
- Single owner
[writable]The source account.[]The token mint.[]The delegate.[signer]The source account owner.
- Multisignature owner
[writable]The source account.[]The token mint.[]The delegate.[]The source account’s multisignature owner.- ..
4+M[signer]M signer accounts
Fields
MintToChecked
Mints new tokens to an account. The native mint does not support minting.
This instruction differs from MintTo in that the decimals value is
checked by the caller. This may be useful when creating transactions
offline or within a hardware wallet.
Accounts expected by this instruction:
- Single authority
[writable]The mint.[writable]The account to mint tokens to.[signer]The mint’s minting authority.
- Multisignature authority
[writable]The mint.[writable]The account to mint tokens to.[]The mint’s multisignature mint-tokens authority.- ..
3+M[signer]M signer accounts.
Fields
BurnChecked
Burns tokens by removing them from an account. BurnChecked does not
support accounts associated with the native mint, use CloseAccount
instead.
This instruction differs from Burn in that the decimals value is checked by the caller. This may be useful when creating transactions offline or within a hardware wallet.
Accounts expected by this instruction:
- Single owner/delegate
[writable]The account to burn from.[writable]The token mint.[signer]The account’s owner/delegate.
- Multisignature owner/delegate
[writable]The account to burn from.[writable]The token mint.[]The account’s multisignature owner/delegate.- ..
3+M[signer]M signer accounts.
Fields
InitializeAccount2
Like TokenInstruction::InitializeAccount, but the owner pubkey is
passed via instruction data rather than the accounts list. This
variant may be preferable when using Cross Program Invocation from
an instruction that does not need the owner’s AccountInfo
otherwise.
Accounts expected by this instruction:
[writable]The account to initialize.[]The mint this account will be associated with.[]Rent sysvar
SyncNative
Given a wrapped / native token account (a token account containing SOL)
updates its amount field based on the account’s underlying lamports.
This is useful if a non-wrapped SOL account uses
system_instruction::transfer to move lamports to a wrapped token
account, and needs to have its token amount field updated.
Accounts expected by this instruction:
- Using runtime Rent sysvar
[writable]The native token account to sync with its underlying lamports.
- Using Rent sysvar account
[writable]The native token account to sync with its underlying lamports.[]Rent sysvar.
InitializeAccount3
Like TokenInstruction::InitializeAccount2, but does not require the
Rent sysvar to be provided
Accounts expected by this instruction:
[writable]The account to initialize.[]The mint this account will be associated with.
InitializeMultisig2
Like TokenInstruction::InitializeMultisig, but does not require the
Rent sysvar to be provided
Accounts expected by this instruction:
[writable]The multisignature account to initialize.- ..
1+N[]The signer accounts, must equal to N where1 <= N <= 11.
InitializeMint2
Like TokenInstruction::InitializeMint, but does not require the Rent
sysvar to be provided
Accounts expected by this instruction:
[writable]The mint to initialize.
Fields
The authority/multisignature to mint tokens.
The freeze authority/multisignature of the mint.
GetAccountDataSize
Gets the required size of an account for the given mint as a
little-endian u64.
Return data can be fetched using sol_get_return_data and deserializing
the return data as a little-endian u64.
Accounts expected by this instruction:
[]The mint to calculate for
InitializeImmutableOwner
Initialize the Immutable Owner extension for the given token account
Fails if the account has already been initialized, so must be called
before InitializeAccount.
No-ops in this version of the program, but is included for compatibility with the Associated Token Account program.
Accounts expected by this instruction:
[writable]The account to initialize.
Data expected by this instruction: None
AmountToUiAmount
Convert an Amount of tokens to a UiAmount string, using the given
mint. In this version of the program, the mint can only specify the
number of decimals.
Fails on an invalid mint.
Return data can be fetched using sol_get_return_data and deserialized
with String::from_utf8.
Accounts expected by this instruction:
[]The mint to calculate for
UiAmountToAmount
Convert a UiAmount of tokens to a little-endian u64 raw Amount,
using the given mint. In this version of the program, the mint can
only specify the number of decimals.
Return data can be fetched using sol_get_return_data and deserializing
the return data as a little-endian u64.
Accounts expected by this instruction:
[]The mint to calculate for
WithdrawExcessLamports = 38
This instruction is to be used to rescue SOL sent to any TokenProgram
owned account by sending them to any other account, leaving behind only
lamports for rent exemption.
Accounts expected by this instruction:
- Single owner/delegate
[writable]The source account.[writable]The destination account.[signer]The source account’s owner/delegate.
- Multisignature owner/delegate
[writable]The source account.[writable]The destination account.[]The source account’s multisignature owner/delegate...+M[signer]M signer accounts.
UnwrapLamports
Transfer lamports from a native SOL account to a destination account.
This is useful to unwrap lamports from a wrapped SOL account.
Accounts expected by this instruction:
- Single owner/delegate
[writable]The source account.[writable]The destination account.[signer]The source account’s owner/delegate.
- Multisignature owner/delegate
[writable]The source account.[writable]The destination account.[]The source account’s multisignature owner/delegate...+M[signer]M signer accounts.
Data expected by this instruction:
Option<u64>The amount of lamports to transfer. When an amount is not specified, the entire balance of the source account will be transferred.
Batch = 255
Executes a batch of instructions. The instructions to be executed are specified in sequence on the instruction data. Each instruction provides:
u8: number of accountsu8: instruction data length (includes the discriminator)u8: instruction discriminator[u8]: instruction data
Accounts follow a similar pattern, where accounts for each instruction are specified in sequence. Therefore, the number of accounts expected by this instruction is variable, i.e., it depends on the instructions provided.
Both the number of accounts and instruction data length are used to
identify the slice of accounts and instruction data for each
instruction. Since the instruction data length is specified as a u8,
the maximum instruction data length is 255 bytes, which is sufficient
for all current instructions in the program.
When one or more batched instructions write return data, the batch instruction returns the data written by the last instruction that does so. That instruction does not have to be the final instruction in the batch: later instructions that do not write return data leave the last written return data unchanged.
Note that it is not sound to have a batch instruction that contains
other batch instruction; an error will be raised when this is
detected.
Implementations§
Source§impl<'a> TokenInstruction<'a>
impl<'a> TokenInstruction<'a>
Sourcepub fn unpack(input: &'a [u8]) -> Result<Self, ProgramError>
pub fn unpack(input: &'a [u8]) -> Result<Self, ProgramError>
Unpacks a byte buffer into a
TokenInstruction.
Trait Implementations§
Source§impl<'a> Clone for TokenInstruction<'a>
impl<'a> Clone for TokenInstruction<'a>
Source§fn clone(&self) -> TokenInstruction<'a>
fn clone(&self) -> TokenInstruction<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for TokenInstruction<'a>
impl<'a> Debug for TokenInstruction<'a>
Source§impl<'a> PartialEq for TokenInstruction<'a>
impl<'a> PartialEq for TokenInstruction<'a>
Source§fn eq(&self, other: &TokenInstruction<'a>) -> bool
fn eq(&self, other: &TokenInstruction<'a>) -> bool
self and other values to be equal, and is used by ==.