DeveloperBreeze

Blockchain Development Programming Tutorials, Guides & Best Practices

Explore 30+ expertly crafted blockchain development tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Using Solana's Program Library: Building Applications with Pre-Built Functions

Tutorial August 27, 2024
rust

use anchor_lang::prelude::*;
use spl_token::instruction::mint_to;
use solana_program::program::invoke;

declare_id!("YourProgramID");

#[program]
pub mod solana_spl_tutorial {
    use super::*;

    pub fn mint_token(ctx: Context<MintToken>, amount: u64) -> Result<()> {
        let cpi_accounts = MintTo {
            mint: ctx.accounts.mint.to_account_info(),
            to: ctx.accounts.token_account.to_account_info(),
            authority: ctx.accounts.authority.to_account_info(),
        };
        let cpi_program = ctx.accounts.token_program.to_account_info();
        let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);

        invoke(
            &mint_to(
                ctx.accounts.token_program.key,
                ctx.accounts.mint.key,
                ctx.accounts.token_account.key,
                ctx.accounts.authority.key,
                &[],
                amount,
            )?,
            &[
                ctx.accounts.mint.to_account_info(),
                ctx.accounts.token_account.to_account_info(),
                ctx.accounts.authority.to_account_info(),
            ],
        )?;

        Ok(())
    }
}

#[derive(Accounts)]
pub struct MintToken<'info> {
    #[account(mut)]
    pub mint: AccountInfo<'info>,
    #[account(mut)]
    pub token_account: AccountInfo<'info>,
    #[account(signer)]
    pub authority: AccountInfo<'info>,
    pub token_program: AccountInfo<'info>,
}

This simple program demonstrates how to use the SPL Token Program to mint new tokens.

Essential Websites and Platforms for Solana Developers

Tutorial August 09, 2024

  • A decentralized exchange built on Solana, offering insights into DeFi activities and trading data.
  • Website: serum.exchange
  • A platform to request free SOL tokens for development and testing on Solana's Devnet.
  • Website: solfaucet.com