DeveloperBreeze

Solana Cli Development Tutorials, Guides & Insights

Unlock 3+ expert-curated solana cli tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your solana cli skills on DeveloperBreeze.

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

Tutorial August 27, 2024
rust

Open the lib.rs file inside the programs/solana-spl-tutorial/src directory and replace its content with the following code:

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>,
}

Creating a Token on Solana

Tutorial August 09, 2024
bash rust

   spl-token --version

You should see the version number of the SPL Token CLI.

Installing Solana on Ubuntu

Tutorial August 09, 2024
bash rust

   source $HOME/.cargo/env
   rustc --version