Anchor for EVM Developers
  • Anchor for EVM Developers
  • Program Address
  • Functions
  • Token
  • Validation
  • Mutation
  • Calling Other Contract
  • Wrap Native Token
  • Transfer Native Token
  • Transfer Fungible Token
  • Deploy A Fungible Token
  • Access Control
  • Address Mining
  • Events
  • Forking Mainnet
  • Function Selector
  • Feature Flags
  • Feature Dependencies
  • Migration / Scripts
  • Upgrade Programs
  • Block timestamp
Powered by GitBook
On this page

Token

EVM

contract Token {
  mapping(address user => uint256 balance) public balances;
}

Solana

In Solana, the equivalent of an ERC-20 token is SPL token. For a wallet to receive SPL tokens, a token account for the SPL token has to be created.

#[derive(Accounts)]
pub struct Swap<'info> {
  pub token: Account<'info, Mint>,
  
  #[account(
    init_if_needed,
    payer = buyer,
    associated_token::mint = mint,
    associated_token::authority = buyer
  )]
  pub buyer_token_account: Account<'info, TokenAccount>,
  
  pub buyer: Signer<'info>
}

Here we are using the associated_token_program to initialize the account. mintis the token's address and authorityis the address that controls the token account.

PreviousFunctionsNextValidation

Last updated 2 months ago