Instruction builders for the SPL Token Program.
Works with both SPL Token and Token-2022 via the :token_program option.
SPL Token uses a 1-byte instruction index (unlike System Program's 4-byte u32).
Examples
iex> ix = Cartouche.Solana.TokenProgram.transfer(<<1::256>>, <<2::256>>, <<3::256>>, 1_000_000)
iex> ix.data
<<3, 64, 66, 15, 0, 0, 0, 0, 0>>API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
sync_native | 2 | Build an SPL token sync-native instruction for wrapped SOL accounts. | account: value, opts: value |
close_account | 4 | Build an SPL token close-account instruction. | account: value, destination: value, authority: value, opts: value |
approve | 5 | Build an SPL token approve instruction for a delegate allowance. | source: value, delegate: value, authority: value, amount: value, opts: value |
transfer_checked | 7 | Build an SPL token transfer instruction with mint and decimal verification. | source: value, mint: value, destination: value, authority: value, amount: value, decimals: value, opts: value |
transfer | 5 | Build an SPL token transfer instruction. | source: value, destination: value, authority: value, amount: value, opts: value |
Summary
Functions
Approve a delegate to transfer up to amount tokens from source.
Close a token account, transferring remaining SOL rent to destination.
Sync the native SOL balance of a wrapped SOL token account.
Transfer tokens from source to destination.
Transfer tokens with decimal verification (preferred over transfer/5).
Functions
@spec approve(<<_::256>>, <<_::256>>, <<_::256>>, non_neg_integer(), keyword()) :: Cartouche.Solana.Transaction.Instruction.t()
Approve a delegate to transfer up to amount tokens from source.
Options
:token_program- Override the token program (default: SPL Token Program).
@spec close_account(<<_::256>>, <<_::256>>, <<_::256>>, keyword()) :: Cartouche.Solana.Transaction.Instruction.t()
Close a token account, transferring remaining SOL rent to destination.
Options
:token_program- Override the token program (default: SPL Token Program).
@spec sync_native( <<_::256>>, keyword() ) :: Cartouche.Solana.Transaction.Instruction.t()
Sync the native SOL balance of a wrapped SOL token account.
Options
:token_program- Override the token program (default: SPL Token Program).
@spec transfer(<<_::256>>, <<_::256>>, <<_::256>>, non_neg_integer(), keyword()) :: Cartouche.Solana.Transaction.Instruction.t()
Transfer tokens from source to destination.
The authority must sign the transaction.
Options
:token_program- Override the token program (default: SPL Token Program).
@spec transfer_checked( <<_::256>>, <<_::256>>, <<_::256>>, <<_::256>>, non_neg_integer(), non_neg_integer(), keyword() ) :: Cartouche.Solana.Transaction.Instruction.t()
Transfer tokens with decimal verification (preferred over transfer/5).
Requires passing the mint, preventing accidental wrong-decimal transfers.
Options
:token_program- Override the token program (default: SPL Token Program).