Search documentation of Cartouche

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

Copy Markdown View Source

Associated Token Account (ATA) utilities for Solana.

An ATA is the canonical token account for a (wallet, mint) pair. It is a PDA derived with seeds `[wallet, token_program_id, mint]` under the Associated Token Account Program.

## Examples

    iex> {pub, _} = Cartouche.Solana.Keys.from_seed(<<1::256>>)
    iex> mint = Cartouche.Solana.Programs.wrapped_sol_mint()
    iex> {ata, bump} = Cartouche.Solana.ATA.find_address(pub, mint)
    iex> byte_size(ata) == 32 and bump >= 0 and bump <= 255
    true

## Summary

### Functions

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

Build an instruction to create an ATA. Fails if it already exists.

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

Build an instruction to create an ATA, succeeding even if it already exists.

find_address(arg1, arg2, opts \\ [])

Derive the associated token account address for a wallet + mint.

## Functions

# create(arg1, arg2, arg3, opts \\ [])

    @spec create(<<_::256>>, <<_::256>>, <<_::256>>, keyword()) ::
      Cartouche.Solana.Transaction.Instruction.t()

Build an instruction to create an ATA. Fails if it already exists.

## Options

- `:token_program` - Override the token program (default: SPL Token Program).

# create_idempotent(arg1, arg2, arg3, opts \\ [])

    @spec create_idempotent(<<_::256>>, <<_::256>>, <<_::256>>, keyword()) ::
      Cartouche.Solana.Transaction.Instruction.t()

Build an instruction to create an ATA, succeeding even if it already exists.

This is the preferred variant for most use cases - it is a no-op if the ATA already exists.

## Options

- `:token_program` - Override the token program (default: SPL Token Program).

# find_address(arg1, arg2, opts \\ [])

    @spec find_address(<<_::256>>, <<_::256>>, keyword()) ::
      {<<_::256>>, non_neg_integer()}

Derive the associated token account address for a wallet + mint.

Pure computation (no RPC call). Returns `{ata_address, bump_seed}`.

## Options

- `:token_program` - Override the token program (default: SPL Token Program). Pass `Programs.token_2022_program()` for Token-2022 mints.