- 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 Guide
Compare to SPL:
1
Prerequisites
Dependencies
Dependencies
Cargo.toml
Report incorrect code
Copy
Ask AI
[dependencies]
light-compressed-token-sdk = "0.1"
light-client = "0.1"
light-token-types = "0.1"
solana-sdk = "2.2"
borsh = "0.10"
tokio = { version = "1.36", features = ["full"] }
[dev-dependencies]
light-program-test = "0.1" # For in-memory tests with LiteSVM
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@alpha
Report incorrect code
Copy
Ask AI
yarn global add @lightprotocol/zk-compression-cli@alpha
Report incorrect code
Copy
Ask AI
pnpm add -g @lightprotocol/zk-compression-cli@alpha
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(())
}
2
Burn light-tokens
View Source Code or find full examples with tests: examples-light-token.
Report incorrect code
Copy
Ask AI
mod shared;
use borsh::BorshDeserialize;
use light_client::rpc::Rpc;
use light_token_sdk::token::Burn;
use shared::SetupContext;
use solana_sdk::signer::Signer;
#[tokio::test(flavor = "multi_thread")]
async fn burn() {
// Setup creates mint and ATA with tokens
let SetupContext {
mut rpc,
payer,
mint,
ata,
..
} = shared::setup().await;
let initial_amount = 1_000_000u64;
let burn_amount = 400_000u64;
let burn_ix = Burn {
source: ata,
mint,
amount: burn_amount,
authority: payer.pubkey(),
max_top_up: None,
}
.instruction()
.unwrap();
rpc.create_and_send_transaction(&[burn_ix], &payer.pubkey(), &[&payer])
.await
.unwrap();
let ata_data = rpc.get_account(ata).await.unwrap().unwrap();
let token = light_token_interface::state::Token::deserialize(&mut &ata_data.data[..]).unwrap();
assert_eq!(token.amount, initial_amount - burn_amount);
}
1
Build Account Infos and CPI
- invoke (External Signer)
- invoke_signed (PDA Authority)
Report incorrect code
Copy
Ask AI
use light_token_sdk::token::BurnCpi;
BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
max_top_up: None,
}
.invoke()
Report incorrect code
Copy
Ask AI
use light_token_sdk::token::BurnCpi;
let signer_seeds = authority_seeds!(bump);
BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
max_top_up: None,
}
.invoke_signed(&[signer_seeds])
Full Code Example
View Source Code or full examples with tests: examples-light-token.
- Anchor
- Native
Report incorrect code
Copy
Ask AI
#![allow(unexpected_cfgs)]
use anchor_lang::prelude::*;
use light_token_sdk::token::BurnCpi;
declare_id!("BHTGZDjDw9Gpz8oYm7CRMg2WtKwW65YAYHXXMKv4dpr6");
#[program]
pub mod light_token_anchor_burn {
use super::*;
pub fn burn<'info>(
ctx: Context<'_, '_, '_, 'info, BurnAccounts<'info>>,
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(),
max_top_up: None,
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct BurnAccounts<'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>,
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
}
Report incorrect code
Copy
Ask AI
use super::authority_seeds;
use light_token_sdk::token::BurnCpi;
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult,
program_error::ProgramError,
};
pub fn burn_invoke(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
let [source, mint, authority, _token_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
let amount = u64::from_le_bytes(
data.try_into()
.map_err(|_| ProgramError::InvalidInstructionData)?,
);
BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
max_top_up: None,
}
.invoke()
}
pub fn burn_invoke_signed(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
let [source, mint, authority, _token_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
if data.len() < 9 {
return Err(ProgramError::InvalidInstructionData);
}
let amount = u64::from_le_bytes(data[0..8].try_into().unwrap());
let bump = data[8];
let signer_seeds = authority_seeds!(bump);
BurnCpi {
source: source.clone(),
mint: mint.clone(),
amount,
authority: authority.clone(),
max_top_up: None,
}
.invoke_signed(&[signer_seeds])
}