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.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Using Solana's Program Library: Building Applications with Pre-Built Functions
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
You should see the version number of the SPL Token CLI.
Use the SPL Token CLI to create a new token. This command will generate a new token mint address:
Installing Solana on Ubuntu
sudo apt update
sudo apt upgrade -ySolana requires several dependencies to be installed on your system. Use the following commands to install them: