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-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
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 Source Code or find full examples with tests: examples-light-token.
mod shared;

use light_client::rpc::Rpc;
use light_token_sdk::token::{CloseAccount, LIGHT_TOKEN_PROGRAM_ID};
use shared::SetupContext;
use solana_sdk::signer::Signer;

#[tokio::test(flavor = "multi_thread")]
async fn close_account() {
    // Setup creates mint and empty ATA (must be empty to close).
    let SetupContext {
        mut rpc,
        payer,
        ata,
        ..
    } = shared::setup_empty_ata().await;
    let close_ix = CloseAccount::new(
        LIGHT_TOKEN_PROGRAM_ID,
        ata,
        payer.pubkey(),
        payer.pubkey(),
    )
    .instruction()
    .unwrap();

    rpc.create_and_send_transaction(&[close_ix], &payer.pubkey(), &[&payer])
        .await
        .unwrap();

    let account_after = rpc.get_account(ata).await.unwrap();
    assert!(account_after.is_none());
}

Next Steps

Use the Unified Transfer Interface for Light-Token, SPL and Token 22 Transfers