Enum spl_token_2022::instruction::TokenInstruction

source ·
#[repr(C)]
pub enum TokenInstruction<'a> {
Show 42 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 { extension_types: Vec<ExtensionType>, }, InitializeImmutableOwner, AmountToUiAmount { amount: u64, }, UiAmountToAmount { ui_amount: &'a str, }, InitializeMintCloseAuthority { close_authority: COption<Pubkey>, }, TransferFeeExtension, ConfidentialTransferExtension, DefaultAccountStateExtension, Reallocate { extension_types: Vec<ExtensionType>, }, MemoTransferExtension, CreateNativeMint, InitializeNonTransferableMint, InterestBearingMintExtension, CpiGuardExtension, InitializePermanentDelegate { delegate: Pubkey, }, TransferHookExtension, ConfidentialTransferFeeExtension, WithdrawExcessLamports, MetadataPointerExtension, GroupPointerExtension, GroupMemberPointerExtension,
}
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.

All extensions must be initialized before calling this instruction.

Accounts expected by this instruction:

  1. [writable] The mint to initialize.
  2. [] Rent sysvar

Fields

§decimals: u8

Number of base 10 digits to the right of the decimal place.

§mint_authority: Pubkey

The authority/multisignature to mint tokens.

§freeze_authority: COption<Pubkey>

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:

  1. [writable] The account to initialize.
  2. [] The mint this account will be associated with.
  3. [] The new account’s owner/multisignature.
  4. [] 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:

  1. [writable] The multisignature account to initialize.
  2. [] Rent sysvar
  3. ..2+N. [] The signer accounts, must equal to N where 1 <= N <= 11.

Fields

§m: u8

The number of signers (M) required to validate this multisignature account.

§

Transfer

👎Deprecated since 4.0.0: please use TransferChecked or TransferCheckedWithFee instead

NOTE This instruction is deprecated in favor of TransferChecked or TransferCheckedWithFee

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.

If either account contains an TransferFeeAmount extension, this will fail. Mints with the TransferFeeConfig extension are required in order to assess the fee.

Accounts expected by this instruction:

  • Single owner/delegate
  1. [writable] The source account.
  2. [writable] The destination account.
  3. [signer] The source account’s owner/delegate.
  • Multisignature owner/delegate
  1. [writable] The source account.
  2. [writable] The destination account.
  3. [] The source account’s multisignature owner/delegate.
  4. ..3+M [signer] M signer accounts.

Fields

§amount: u64
👎Deprecated since 4.0.0: please use TransferChecked or TransferCheckedWithFee instead

The amount of tokens to transfer.

§

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
  1. [writable] The source account.
  2. [] The delegate.
  3. [signer] The source account owner.
  • Multisignature owner
  1. [writable] The source account.
  2. [] The delegate.
  3. [] The source account’s multisignature owner.
  4. ..3+M [signer] M signer accounts

Fields

§amount: u64

The amount of tokens the delegate is approved for.

§

Revoke

Revokes the delegate’s authority.

Accounts expected by this instruction:

  • Single owner
  1. [writable] The source account.
  2. [signer] The source account owner or current delegate.
  • Multisignature owner
  1. [writable] The source account.
  2. [] The source account’s multisignature owner or current delegate.
  3. ..2+M [signer] M signer accounts
§

SetAuthority

Sets a new authority of a mint or account.

Accounts expected by this instruction:

  • Single authority
  1. [writable] The mint or account to change the authority of.
  2. [signer] The current authority of the mint or account.
  • Multisignature authority
  1. [writable] The mint or account to change the authority of.
  2. [] The mint’s or account’s current multisignature authority.
  3. ..2+M [signer] M signer accounts

Fields

§authority_type: AuthorityType

The type of authority to update.

§new_authority: COption<Pubkey>

The new authority

§

MintTo

Mints new tokens to an account. The native mint does not support minting.

Accounts expected by this instruction:

  • Single authority
  1. [writable] The mint.
  2. [writable] The account to mint tokens to.
  3. [signer] The mint’s minting authority.
  • Multisignature authority
  1. [writable] The mint.
  2. [writable] The account to mint tokens to.
  3. [] The mint’s multisignature mint-tokens authority.
  4. ..3+M [signer] M signer accounts.

Fields

§amount: u64

The amount of new tokens to mint.

§

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
  1. [writable] The account to burn from.
  2. [writable] The token mint.
  3. [signer] The account’s owner/delegate.
  • Multisignature owner/delegate
  1. [writable] The account to burn from.
  2. [writable] The token mint.
  3. [] The account’s multisignature owner/delegate.
  4. ..3+M [signer] M signer accounts.

Fields

§amount: u64

The amount of tokens to burn.

§

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 with the TransferFeeAmount extension may only be closed if the withheld amount is zero.

Accounts with the ConfidentialTransfer extension may only be closed if the pending and available balance ciphertexts are empty. Use ConfidentialTransferInstruction::ApplyPendingBalance and ConfidentialTransferInstruction::EmptyAccount to empty these ciphertexts.

Accounts with the ConfidentialTransferFee extension may only be closed if the withheld amount ciphertext is empty. Use ConfidentialTransferFeeInstruction::HarvestWithheldTokensToMint to empty this ciphertext.

Mints may be closed if they have the MintCloseAuthority extension and their token supply is zero

Accounts

Accounts expected by this instruction:

  • Single owner
  1. [writable] The account to close.
  2. [writable] The destination account.
  3. [signer] The account’s owner.
  • Multisignature owner
  1. [writable] The account to close.
  2. [writable] The destination account.
  3. [] The account’s multisignature owner.
  4. ..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
  1. [writable] The account to freeze.
  2. [] The token mint.
  3. [signer] The mint freeze authority.
  • Multisignature owner
  1. [writable] The account to freeze.
  2. [] The token mint.
  3. [] The mint’s multisignature freeze authority.
  4. ..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
  1. [writable] The account to freeze.
  2. [] The token mint.
  3. [signer] The mint freeze authority.
  • Multisignature owner
  1. [writable] The account to freeze.
  2. [] The token mint.
  3. [] The mint’s multisignature freeze authority.
  4. ..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.

If either account contains an TransferFeeAmount extension, the fee is withheld in the destination account.

Accounts expected by this instruction:

  • Single owner/delegate
  1. [writable] The source account.
  2. [] The token mint.
  3. [writable] The destination account.
  4. [signer] The source account’s owner/delegate.
  • Multisignature owner/delegate
  1. [writable] The source account.
  2. [] The token mint.
  3. [writable] The destination account.
  4. [] The source account’s multisignature owner/delegate.
  5. ..4+M [signer] M signer accounts.

Fields

§amount: u64

The amount of tokens to transfer.

§decimals: u8

Expected number of base 10 digits to the right of the decimal place.

§

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
  1. [writable] The source account.
  2. [] The token mint.
  3. [] The delegate.
  4. [signer] The source account owner.
  • Multisignature owner
  1. [writable] The source account.
  2. [] The token mint.
  3. [] The delegate.
  4. [] The source account’s multisignature owner.
  5. ..4+M [signer] M signer accounts

Fields

§amount: u64

The amount of tokens the delegate is approved for.

§decimals: u8

Expected number of base 10 digits to the right of the decimal place.

§

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
  1. [writable] The mint.
  2. [writable] The account to mint tokens to.
  3. [signer] The mint’s minting authority.
  • Multisignature authority
  1. [writable] The mint.
  2. [writable] The account to mint tokens to.
  3. [] The mint’s multisignature mint-tokens authority.
  4. ..3+M [signer] M signer accounts.

Fields

§amount: u64

The amount of new tokens to mint.

§decimals: u8

Expected number of base 10 digits to the right of the decimal place.

§

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
  1. [writable] The account to burn from.
  2. [writable] The token mint.
  3. [signer] The account’s owner/delegate.
  • Multisignature owner/delegate
  1. [writable] The account to burn from.
  2. [writable] The token mint.
  3. [] The account’s multisignature owner/delegate.
  4. ..3+M [signer] M signer accounts.

Fields

§amount: u64

The amount of tokens to burn.

§decimals: u8

Expected number of base 10 digits to the right of the decimal place.

§

InitializeAccount2

Like 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:

  1. [writable] The account to initialize.
  2. [] The mint this account will be associated with.
  3. [] Rent sysvar

Fields

§owner: Pubkey

The new account’s owner/multisignature.

§

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:

  1. [writable] The native token account to sync with its underlying lamports.
§

InitializeAccount3

Like InitializeAccount2, but does not require the Rent sysvar to be provided

Accounts expected by this instruction:

  1. [writable] The account to initialize.
  2. [] The mint this account will be associated with.

Fields

§owner: Pubkey

The new account’s owner/multisignature.

§

InitializeMultisig2

Like InitializeMultisig, but does not require the Rent sysvar to be provided

Accounts expected by this instruction:

  1. [writable] The multisignature account to initialize.
  2. ..1+N. [] The signer accounts, must equal to N where 1 <= N <= 11.

Fields

§m: u8

The number of signers (M) required to validate this multisignature account.

§

InitializeMint2

Like InitializeMint, but does not require the Rent sysvar to be provided

Accounts expected by this instruction:

  1. [writable] The mint to initialize.

Fields

§decimals: u8

Number of base 10 digits to the right of the decimal place.

§mint_authority: Pubkey

The authority/multisignature to mint tokens.

§freeze_authority: COption<Pubkey>

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:

  1. [] The mint to calculate for

Fields

§extension_types: Vec<ExtensionType>

Additional extension types to include in the returned account size

§

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.

Accounts expected by this instruction:

  1. [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.

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:

  1. [] The mint to calculate for

Fields

§amount: u64

The amount of tokens to convert.

§

UiAmountToAmount

Convert a UiAmount of tokens to a little-endian u64 raw Amount, using the given mint.

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:

  1. [] The mint to calculate for

Fields

§ui_amount: &'a str

The ui_amount of tokens to convert.

§

InitializeMintCloseAuthority

Initialize the close account authority on a new mint.

Fails if the mint has already been initialized, so must be called before InitializeMint.

The mint must have exactly enough space allocated for the base mint (82 bytes), plus 83 bytes of padding, 1 byte reserved for the account type, then space required for this extension, plus any others.

Accounts expected by this instruction:

  1. [writable] The mint to initialize.

Fields

§close_authority: COption<Pubkey>

Authority that must sign the CloseAccount instruction on a mint

§

TransferFeeExtension

The common instruction prefix for Transfer Fee extension instructions.

See extension::transfer_fee::instruction::TransferFeeInstruction for further details about the extended instructions that share this instruction prefix

§

ConfidentialTransferExtension

The common instruction prefix for Confidential Transfer extension instructions.

See extension::confidential_transfer::instruction::ConfidentialTransferInstruction for further details about the extended instructions that share this instruction prefix

§

DefaultAccountStateExtension

The common instruction prefix for Default Account State extension instructions.

See extension::default_account_state::instruction::DefaultAccountStateInstruction for further details about the extended instructions that share this instruction prefix

§

Reallocate

Check to see if a token account is large enough for a list of ExtensionTypes, and if not, use reallocation to increase the data size.

Accounts expected by this instruction:

  • Single owner
  1. [writable] The account to reallocate.
  2. [signer, writable] The payer account to fund reallocation
  3. [] System program for reallocation funding
  4. [signer] The account’s owner.
  • Multisignature owner
  1. [writable] The account to reallocate.
  2. [signer, writable] The payer account to fund reallocation
  3. [] System program for reallocation funding
  4. [] The account’s multisignature owner/delegate.
  5. ..4+M [signer] M signer accounts.

Fields

§extension_types: Vec<ExtensionType>

New extension types to include in the reallocated account

§

MemoTransferExtension

The common instruction prefix for Memo Transfer account extension instructions.

See extension::memo_transfer::instruction::RequiredMemoTransfersInstruction for further details about the extended instructions that share this instruction prefix

§

CreateNativeMint

Creates the native mint.

This instruction only needs to be invoked once after deployment and is permissionless, Wrapped SOL (native_mint::id()) will not be available until this instruction is successfully executed.

Accounts expected by this instruction:

  1. [writeable,signer] Funding account (must be a system account)
  2. [writable] The native mint address
  3. [] System program for mint account funding
§

InitializeNonTransferableMint

Initialize the non transferable extension for the given mint account

Fails if the account has already been initialized, so must be called before InitializeMint.

Accounts expected by this instruction:

  1. [writable] The mint account to initialize.

Data expected by this instruction: None

§

InterestBearingMintExtension

The common instruction prefix for Interest Bearing extension instructions.

See extension::interest_bearing_mint::instruction::InterestBearingMintInstruction for further details about the extended instructions that share this instruction prefix

§

CpiGuardExtension

The common instruction prefix for CPI Guard account extension instructions.

See extension::cpi_guard::instruction::CpiGuardInstruction for further details about the extended instructions that share this instruction prefix

§

InitializePermanentDelegate

Initialize the permanent delegate on a new mint.

Fails if the mint has already been initialized, so must be called before InitializeMint.

The mint must have exactly enough space allocated for the base mint (82 bytes), plus 83 bytes of padding, 1 byte reserved for the account type, then space required for this extension, plus any others.

Accounts expected by this instruction:

  1. [writable] The mint to initialize.

Data expected by this instruction: Pubkey for the permanent delegate

Fields

§delegate: Pubkey

Authority that may sign for Transfers and Burns on any account

§

TransferHookExtension

The common instruction prefix for transfer hook extension instructions.

See extension::transfer_hook::instruction::TransferHookInstruction for further details about the extended instructions that share this instruction prefix

§

ConfidentialTransferFeeExtension

The common instruction prefix for the confidential transfer fee extension instructions.

See extension::confidential_transfer_fee::instruction::ConfidentialTransferFeeInstruction for further details about the extended instructions that share this instruction prefix

§

WithdrawExcessLamports

This instruction is to be used to rescue SOLs sent to any TokenProgram owned account by sending them to any other account, leaving behind only lamports for rent exemption.

  1. [writable] Source Account owned by the token program
  2. [writable] Destination account
  3. [signer] Authority
  4. ..2+M [signer] M signer accounts.
§

MetadataPointerExtension

The common instruction prefix for metadata pointer extension instructions.

See extension::metadata_pointer::instruction::MetadataPointerInstruction for further details about the extended instructions that share this instruction prefix

§

GroupPointerExtension

The common instruction prefix for group pointer extension instructions.

See extension::group_pointer::instruction::GroupPointerInstruction for further details about the extended instructions that share this instruction prefix

§

GroupMemberPointerExtension

The common instruction prefix for group member pointer extension instructions.

See extension::group_member_pointer::instruction::GroupMemberPointerInstruction for further details about the extended instructions that share this instruction prefix

Implementations§

source§

impl<'a> TokenInstruction<'a>

source

pub fn unpack(input: &'a [u8]) -> Result<Self, ProgramError>

Unpacks a byte buffer into a TokenInstruction.

source

pub fn pack(&self) -> Vec<u8>

Packs a TokenInstruction into a byte buffer.

Trait Implementations§

source§

impl<'a> Clone for TokenInstruction<'a>

source§

fn clone(&self) -> TokenInstruction<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for TokenInstruction<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for TokenInstruction<'a>

source§

fn eq(&self, other: &TokenInstruction<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> StructuralPartialEq for TokenInstruction<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for TokenInstruction<'a>

§

impl<'a> RefUnwindSafe for TokenInstruction<'a>

§

impl<'a> Send for TokenInstruction<'a>

§

impl<'a> Sync for TokenInstruction<'a>

§

impl<'a> Unpin for TokenInstruction<'a>

§

impl<'a> UnwindSafe for TokenInstruction<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V