Skip to main content

  1. Light token accounts are Solana accounts that hold token balances of light, SPL, or Token 2022 mints.
  2. Light token accounts are on-chain accounts like SPL ATA’s, but the light token program sponsors the rent-exemption cost for you.
  1. The rent-exemption for light account creation is sponsored by the Light Token Program.
  2. Transaction payer’s pay rent
    to keep accounts “active”
  3. “Inactive” accounts (rent below one epoch) get automatically compressed.
  4. The account’s state is cryptographically preserved and will be loaded into hot account state in-flight, when the account is used again.
The hot state fee is paid for by the transaction payer when writing to the respective account:
  • At account creation ~17,208 lamports
    and .
  • When the account’s rent is below 3h, the transaction payer tops up 776 lamports.
CreateTokenAccount creates an on-chain token account to store token balances of light, SPL, or Token 2022 mints.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

Create 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::CreateTokenAccount;
use shared::SplMintContext;
use solana_sdk::{signature::Keypair, signer::Signer};

#[tokio::test(flavor = "multi_thread")]
async fn create_token_account() {
    // Setup creates mint
    // You can use light, spl, t22 mints to create a light token account.
    let SplMintContext {
        mut rpc,
        payer,
        mint,
    } = shared::setup_spl_mint_context().await;

    let account = Keypair::new();

    let create_account_ix = CreateTokenAccount::new(
        payer.pubkey(),
        account.pubkey(),
        mint,
        payer.pubkey(),
    )
    .instruction()
    .unwrap();

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

    let account_data = rpc.get_account(account.pubkey()).await.unwrap();
    assert!(account_data.is_some());
}

Next Steps

Mint to Light Token Accounts