- Burn permanently destroys tokens by reducing the balance in a token account.
- Burned tokens are removed from circulation and decreases the supply tracked on the mint account.
- Only the token account owner (or approved delegate) can burn tokens.
- Rust Client
- Program
Compare to SPL:
Prerequisites
Dependencies
Dependencies
Cargo.toml
Report incorrect code
Copy
Ask AI
[dependencies]
light-token = "0.4.0"
light-client = { version = "0.19.0", features = ["v2"] }
solana-sdk = "2"
borsh = "0.10.4"
tokio = { version = "1", features = ["full"] }
Developer Environment
Developer Environment
- In-Memory (LightProgramTest)
- Localnet (LightClient)
- Devnet (LightClient)
Test with Lite-SVM (…)
Report incorrect code
Copy
Ask AI
# Initialize project
cargo init my-light-project
cd my-light-project
# Run tests
cargo test
Report incorrect code
Copy
Ask AI
use light_program_test::{LightProgramTest, ProgramTestConfig};
use solana_sdk::signer::Signer;
#[tokio::test]
async fn test_example() {
// In-memory test environment
let mut rpc = LightProgramTest::new(ProgramTestConfig::default())
.await
.unwrap();
let payer = rpc.get_payer().insecure_clone();
println!("Payer: {}", payer.pubkey());
}
Connects to a local test validator.
- npm
- yarn
- pnpm
Report incorrect code
Copy
Ask AI
npm install -g @lightprotocol/zk-compression-cli@beta
Report incorrect code
Copy
Ask AI
yarn global add @lightprotocol/zk-compression-cli@beta
Report incorrect code
Copy
Ask AI
pnpm add -g @lightprotocol/zk-compression-cli@beta
Report incorrect code
Copy
Ask AI
# Initialize project
cargo init my-light-project
cd my-light-project
# Start local test validator (in separate terminal)
light test-validator
Report incorrect code
Copy
Ask AI
use light_client::rpc::{LightClient, LightClientConfig, Rpc};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connects to http://localhost:8899
let rpc = LightClient::new(LightClientConfig::local()).await?;
let slot = rpc.get_slot().await?;
println!("Current slot: {}", slot);
Ok(())
}
Replace
<your-api-key> with your actual API key. Get your API key here.Report incorrect code
Copy
Ask AI
use light_client::rpc::{LightClient, LightClientConfig, Rpc};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rpc_url = "https://devnet.helius-rpc.com?api-key=<your_api_key>";
let rpc = LightClient::new(
LightClientConfig::new(rpc_url.to_string(), None, None)
).await?;
println!("Connected to Devnet");
Ok(())
}
Burn Light Tokens
View the source code and full example with shared test utilities.
- Instruction
Report incorrect code
Copy
Ask AI
use borsh::BorshDeserialize;
use light_client::rpc::Rpc;
use light_token::instruction::Burn;
use rust_client::{setup, SetupContext};
use solana_sdk::signer::Signer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup creates mint and associated token account with tokens
let SetupContext {
mut rpc,
payer,
mint,
associated_token_account,
..
} = setup().await;
let burn_amount = 400_000u64;
let burn_instruction = Burn {
source: associated_token_account,
mint,
amount: burn_amount,
authority: payer.pubkey(),
max_top_up: None,
fee_payer: None,
}
.instruction()?;
let sig = rpc
.create_and_send_transaction(&[burn_instruction], &payer.pubkey(), &[&payer])
.await?;
let data = rpc.get_account(associated_token_account).await?.ok_or("Account not found")?;
let token = light_token_interface::state::Token::deserialize(&mut &data.data[..])?;
println!("Balance: {} Tx: {sig}", token.amount);
Ok(())
}
Build Account Infos and CPI the Light Token Program
Useinvoke for external signers or invoke_signed when the authority is a PDA.- invoke (External signer)
- invoke_signed (PDA owner)
Report incorrect code
Copy
Ask AI
use light_token::instruction::BurnCpi;
BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
system_program: system_program.clone(),
fee_payer: None,
max_top_up: None,
}
.invoke()
Report incorrect code
Copy
Ask AI
use light_token::instruction::BurnCpi;
BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
system_program: system_program.clone(),
fee_payer: None,
max_top_up: None,
}
.invoke_signed(&[signer_seeds])
Full Code Example
View the source code and full example with shared test utilities.
Report incorrect code
Copy
Ask AI
#![allow(unexpected_cfgs, deprecated)]
use anchor_lang::prelude::*;
use light_token::instruction::BurnCpi;
declare_id!("2TXVn8AqjfyeJvmFBD3kHJmh6fWkC4HNB5T76BmLKV5c");
#[program]
pub mod light_token_anchor_burn {
use super::*;
pub fn burn(ctx: Context<BurnAccounts>, amount: u64) -> Result<()> {
BurnCpi {
source: ctx.accounts.source.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
amount,
authority: ctx.accounts.authority.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
max_top_up: None,
fee_payer: None,
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct BurnAccounts<'info> {
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub source: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub mint: AccountInfo<'info>,
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}