Transfer Instruction
Moves tokens from one account to another. This is the basic operation for sending tokens between users.
Before we can transfer any token, we'll need to already have:
Initialized a
Mintaccount.A source
Tokenaccount orAssociated Tokenaccount that already has at least the amount we want to transfer.A destination
Tokenaccount orAssociated Tokenaccount that will receive the tokens from the sourceTokenaccount.
This is how the CPI to the transfer() instruction looks like:
rust
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,
)?;