Skip to main content

  1. Closing a Light Token account transfers remaining lamports to a destination account and the rent sponsor can reclaim sponsored rent.
  2. Light token accounts can be closed by the owner.
The closes the account and preserves the balance as compressed token account when the account becomes . The account is reinstated in flight with the same state the next time it is accessed.
Use CloseTokenAccount to close an empty Light Token account.Compare to SPL:
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

Close Light Token Account

View the source code and full example with shared test utilities.
use light_client::rpc::Rpc;
use light_token::instruction::{CloseAccount, LIGHT_TOKEN_PROGRAM_ID};
use rust_client::{setup_empty_associated_token_account, SetupContext};
use solana_sdk::signer::Signer;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Setup creates mint and empty associated token account (must be empty to close).
    let SetupContext {
        mut rpc,
        payer,
        associated_token_account,
        ..
    } = setup_empty_associated_token_account().await;
    let close_instruction = CloseAccount::new(LIGHT_TOKEN_PROGRAM_ID, associated_token_account, payer.pubkey(), payer.pubkey())
        .instruction()?;

    let sig = rpc
        .create_and_send_transaction(&[close_instruction], &payer.pubkey(), &[&payer])
        .await?;

    let account = rpc.get_account(associated_token_account).await?;
    println!("Closed: {} Tx: {sig}", account.is_none());

    Ok(())
}

Next Steps

Go back to the overview for the Light Token standard.