Anchor
SPL Token with Anchor

SPL Token with Anchor

Transfer Instruction

Moves tokens from one account to another. This is the basic operation for sending tokens between users.

Before we can mint any token, we'll need to already have:

  • Initialized a Mint account.
  • A source Token account or Associated Token account that already has at least the amount we want to transfer.
  • A destination Token account or Associated Token account that will receive the tokens from the source Token account.

The amount of tokens we transfer are "normalized" for decimals. This means that if we want to transfer 1 token that has 6 decimals, we'll need to actually put 1_000_000 as amount

This is how the CPI to the transfer() instruction looks like:

transfer(
    CpiContext::new(
        ctx.accounts.token_program.to_account_info(),
        Transfer {
            from: ctx.accounts.from_token_account.to_account_info(),
            to: ctx.accounts.to_token_account.to_account_info(),
            authority: ctx.accounts.authority.to_account_info(),
        },
    ),
    &1_000_000,
)?;
Contents
View Source
Blueshift © 2025Commit: dd6c76d