1. Home
  2. /
  3. Anchor
  4. /
  5. Token Mint Example

Token Mint Example - Anchor Typing CST Test

Loading…

Token Mint Example — Anchor Code

Defines a simple Anchor program to mint SPL tokens to a user.

#[program]
mod token_mint {
	use super::*;
	pub fn mint_tokens(ctx: Context<MintTokens>, amount: u64) -> Result<()> {
		let cpi_accounts = token::MintTo {
		mint: ctx.accounts.mint.to_account_info(),
		to: ctx.accounts.receiver.to_account_info(),
		authority: ctx.accounts.authority.to_account_info(),
		};
		let cpi_program = ctx.accounts.token_program.to_account_info();
		token::mint_to(CpiContext::new(cpi_program, cpi_accounts), amount)?;
		Ok(())
	}
}

Anchor Language Guide

Anchor is a Rust-based framework for Solana smart contract (program) development, testing, and deployment. It simplifies building Solana dApps by providing a high-level abstraction over Solana programs and client interactions.

Primary Use Cases

  • ▸Writing Solana smart contracts in Rust
  • ▸Generating client interfaces (IDL) for programs
  • ▸Testing programs with simulated Solana clusters
  • ▸Deploying Solana programs to devnet/testnet/mainnet
  • ▸Automating transactions and client-side interactions

Notable Features

  • ▸Rust-based Solana program development
  • ▸IDL generation for client libraries
  • ▸Anchor CLI for scaffolding, building, and deploying programs
  • ▸Testing framework integrated with Solana local validator
  • ▸Macros to reduce boilerplate for accounts, instructions, and errors

Origin & Creator

Anchor was created by Project Serum team members in 2020 to simplify Solana program development, reduce boilerplate, and improve developer productivity.

Industrial Note

Anchor is widely used in DeFi, NFT, and other Solana ecosystem projects, as it standardizes Solana program structure and automates common patterns like account validation and serialization.

More Anchor Typing Exercises

Anchor Simple Counter ProgramAnchor Initialize Account ExampleAnchor Transfer SOL ExampleAnchor PDA ExampleAnchor Multisig ExampleAnchor Escrow ExampleAnchor Event Emission ExampleAnchor Custom Error ExampleAnchor Program With Seeds Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher