Skip to main content

  1. Freeze prevents all transfers or token burns from a specific Light Token account.
  2. Once frozen, the account cannot send tokens, receive tokens, or be closed until it is thawed.
  3. Thaw re-enables transfers on a frozen Light Token account.
  4. Only the freeze authority (set at mint creation) can freeze or thaw accounts.
  5. If the freeze authority is revoked (set to null) on the mint account, tokens can never be frozen.
1

Prerequisites

Cargo.toml
[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"] }
Test with Lite-SVM (…)
# Initialize project
cargo init my-light-project
cd my-light-project

# Run tests
cargo test
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());
}
2

Freeze or thaw Light Token accounts

View the source code and full example with shared test utilities.
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(())
}

Next Steps

Learn to approve and revoke delegates