Cartouche.Solana.TokenProgram (Cartouche v0.1.0)

Copy Markdown View Source

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

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

approve(arg1, arg2, arg3, amount, opts \\ [])

@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).

close_account(arg1, arg2, arg3, opts \\ [])

@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).

sync_native(arg, opts \\ [])

@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).

transfer(arg1, arg2, arg3, amount, opts \\ [])

@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).

transfer_checked(arg1, arg2, arg3, arg4, amount, decimals, opts \\ [])

@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).