- Freeze prevents all transfers or token burns from a specific Light Token account.
- Once frozen, the account cannot send tokens, receive tokens, or be closed until it is thawed.
- Thaw re-enables transfers on a frozen Light Token account.
- Only the freeze authority (set at mint creation) can freeze or thaw accounts.
- If the freeze authority is revoked (set to null) on the mint account, tokens can never be frozen.
- Rust Client
- Program
- Freeze
- Thaw
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(())
}
Freeze or thaw Light Token accounts
View the source code and full example with shared test utilities.
- Freeze
- Thaw
- Instruction
Report incorrect code
Copy
Ask AI
use borsh::BorshDeserialize;
use light_client::rpc::Rpc;
use light_token::instruction::Freeze;
use rust_client::{setup, SetupContext};
use solana_sdk::signer::Signer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup creates mint, associated token account with tokens, and approves delegate
let SetupContext {
mut rpc,
payer,
mint,
associated_token_account,
..
} = setup().await;
// freeze_authority must match what was set during mint creation.
let freeze_instruction = Freeze {
token_account: associated_token_account,
mint,
freeze_authority: payer.pubkey(),
}
.instruction()?;
let sig = rpc
.create_and_send_transaction(&[freeze_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!("State: {:?} Tx: {sig}", token.state);
Ok(())
}
- Instruction
Report incorrect code
Copy
Ask AI
use borsh::BorshDeserialize;
use light_client::rpc::Rpc;
use light_token::instruction::Thaw;
use rust_client::{setup_frozen, SetupContext};
use solana_sdk::signer::Signer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Setup creates mint, associated token account with tokens, and freezes account
let SetupContext {
mut rpc,
payer,
mint,
associated_token_account,
..
} = setup_frozen().await;
let thaw_instruction = Thaw {
token_account: associated_token_account,
mint,
freeze_authority: payer.pubkey(),
}
.instruction()?;
let sig = rpc
.create_and_send_transaction(&[thaw_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!("State: {:?} Tx: {sig}", token.state);
Ok(())
}
- Freeze
- Thaw
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 authority)
Report incorrect code
Copy
Ask AI
use light_token::instruction::FreezeCpi;
FreezeCpi {
token_account: ctx.accounts.token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
freeze_authority: ctx.accounts.freeze_authority.to_account_info(),
}
.invoke()?;
Report incorrect code
Copy
Ask AI
use light_token::instruction::FreezeCpi;
let signer_seeds = authority_seeds!(bump);
FreezeCpi {
token_account: token_account.clone(),
mint: mint.clone(),
freeze_authority: freeze_authority.clone(),
}
.invoke_signed(&[signer_seeds])
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 authority)
Report incorrect code
Copy
Ask AI
use light_token::instruction::ThawCpi;
ThawCpi {
token_account: ctx.accounts.token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
freeze_authority: ctx.accounts.freeze_authority.to_account_info(),
}
.invoke()?;
Report incorrect code
Copy
Ask AI
use light_token::instruction::ThawCpi;
let signer_seeds = authority_seeds!(bump);
ThawCpi {
token_account: token_account.clone(),
mint: mint.clone(),
freeze_authority: freeze_authority.clone(),
}
.invoke_signed(&[signer_seeds])
Full Code Example
- Freeze
- Thaw
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::FreezeCpi;
declare_id!("JBMzMJX4sqCQfNVbosP2oqP1KZ5ZDWiwYTrupk687qXZ");
#[program]
pub mod light_token_anchor_freeze {
use super::*;
pub fn freeze(ctx: Context<FreezeAccounts>) -> Result<()> {
FreezeCpi {
token_account: ctx.accounts.token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
freeze_authority: ctx.accounts.freeze_authority.to_account_info(),
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct FreezeAccounts<'info> {
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub token_account: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub mint: AccountInfo<'info>,
pub freeze_authority: Signer<'info>,
}
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::ThawCpi;
declare_id!("7j94EF5hSkDLf7R26bjrd8Qc6s3oLAQpcKiF3re8JYw9");
#[program]
pub mod light_token_anchor_thaw {
use super::*;
pub fn thaw(ctx: Context<ThawAccounts>) -> Result<()> {
ThawCpi {
token_account: ctx.accounts.token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
freeze_authority: ctx.accounts.freeze_authority.to_account_info(),
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct ThawAccounts<'info> {
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub token_account: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub mint: AccountInfo<'info>,
pub freeze_authority: Signer<'info>,
}