Search documentation of Cartouche

# Cartouche.Solana.TokenProgram (Cartouche v0.1.2)

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(arg1, arg2, arg3, amount, opts \\ [])

Approve a delegate to transfer up to `amount` tokens from source.

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

Close a token account, transferring remaining SOL rent to destination.

sync_native(arg, opts \\ [])

Sync the native SOL balance of a wrapped SOL token account.

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

Transfer tokens from source to destination.

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

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