- Associated Light Token accounts can hold token balances of light, SPL, or Token 2022 mints.
- Light-ATAs are on-chain accounts like SPL ATA’s, but the light token program sponsors the rent-exemption cost for you.
Light Rent Config Explained
Light Rent Config Explained
- A rent sponsor PDA by Light Protocol pays the rent-exemption cost for the account.
- Transaction fee payers bump a virtual rent balance when writing to the account, which keeps the account “hot”.
- “Cold” accounts virtual rent balance below threshold (eg 24h without write bump) get auto-compressed.
- The cold account’s state is cryptographically preserved on the Solana ledger. Users can load a cold account into hot state in-flight when using the account again.
Agent skill
Agent skill
Install the agent skill:See the AI tools guide for dedicated skills.
Report incorrect code
Copy
Ask AI
npx skills add https://zkcompression.com
- TypeScript Client
- Rust Client
- Program
The
createAtaInterface function creates an associated Light Token account in a single call.Compare to SPL:Find the source code
here.
- Guide
- AI Prompt
Create Associated Token Account
Installation
Installation
- npm
- yarn
- pnpm
Install packages in your working directory:Install the CLI globally:
Report incorrect code
Copy
Ask AI
npm install @lightprotocol/stateless.js@beta \
@lightprotocol/compressed-token@beta
Report incorrect code
Copy
Ask AI
npm install -g @lightprotocol/zk-compression-cli@beta
Install packages in your working directory:Install the CLI globally:
Report incorrect code
Copy
Ask AI
yarn add @lightprotocol/stateless.js@beta \
@lightprotocol/compressed-token@beta
Report incorrect code
Copy
Ask AI
yarn global add @lightprotocol/zk-compression-cli@beta
Install packages in your working directory:Install the CLI globally:
Report incorrect code
Copy
Ask AI
pnpm add @lightprotocol/stateless.js@beta \
@lightprotocol/compressed-token@beta
Report incorrect code
Copy
Ask AI
pnpm add -g @lightprotocol/zk-compression-cli@beta
- Localnet
- Devnet
Report incorrect code
Copy
Ask AI
# start local test-validator in a separate terminal
light test-validator
In the code examples, use
createRpc() without arguments for localnet.Get an API key from Helius and add to
.env:.env
Report incorrect code
Copy
Ask AI
API_KEY=<your-helius-api-key>
In the code examples, use
createRpc(RPC_URL) with the devnet URL.- Action
- Instruction
Report incorrect code
Copy
Ask AI
import "dotenv/config";
import { Keypair } from "@solana/web3.js";
import { createRpc } from "@lightprotocol/stateless.js";
import {
createMintInterface,
createAtaInterface,
} from "@lightprotocol/compressed-token";
import { homedir } from "os";
import { readFileSync } from "fs";
// devnet:
const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
const rpc = createRpc(RPC_URL);
// localnet:
// const rpc = createRpc();
const payer = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8"))
)
);
(async function () {
const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
const owner = Keypair.generate();
const ata = await createAtaInterface(rpc, payer, mint, owner.publicKey);
console.log("ATA:", ata.toBase58());
})();
Report incorrect code
Copy
Ask AI
import "dotenv/config";
import {
Keypair,
Transaction,
sendAndConfirmTransaction,
} from "@solana/web3.js";
import { createRpc, LIGHT_TOKEN_PROGRAM_ID } from "@lightprotocol/stateless.js";
import {
createMintInterface,
createAssociatedTokenAccountInterfaceInstruction,
getAssociatedTokenAddressInterface,
} from "@lightprotocol/compressed-token";
import { homedir } from "os";
import { readFileSync } from "fs";
// devnet:
// const RPC_URL = `https://devnet.helius-rpc.com?api-key=${process.env.API_KEY!}`;
// const rpc = createRpc(RPC_URL);
// localnet:
const rpc = createRpc();
const payer = Keypair.fromSecretKey(
new Uint8Array(
JSON.parse(readFileSync(`${homedir()}/.config/solana/id.json`, "utf8")),
),
);
(async function () {
const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
const owner = Keypair.generate();
const associatedToken = getAssociatedTokenAddressInterface(
mint,
owner.publicKey,
);
const ix = createAssociatedTokenAccountInterfaceInstruction(
payer.publicKey,
associatedToken,
owner.publicKey,
mint,
LIGHT_TOKEN_PROGRAM_ID,
);
const tx = new Transaction().add(ix);
const signature = await sendAndConfirmTransaction(rpc, tx, [payer]);
console.log("ATA:", associatedToken.toBase58());
console.log("Tx:", signature);
})();
Create rent-free associated token account
Report incorrect code
Copy
Ask AI
---
description: Create rent-free associated token account
allowed-tools: Bash, Read, Write, Edit, Glob, Grep, WebFetch, AskUserQuestion, Task, TaskCreate, TaskGet, TaskList, TaskUpdate, TaskOutput, mcp__deepwiki, mcp__zkcompression
---
## Create rent-free associated token account
Context:
- Guide: https://zkcompression.com/light-token/cookbook/create-ata
- Skills and resources index: https://zkcompression.com/skill.md
- SPL to Light reference: https://zkcompression.com/api-reference/solana-to-light-comparison
- Packages: @lightprotocol/compressed-token, @lightprotocol/stateless.js
SPL equivalent: createAssociatedTokenAccount() → Light Token: createAtaInterface()
### 1. Index project
- Grep `@solana/spl-token|Connection|Keypair|createAssociatedTokenAccount|createAtaInterface` across src/
- Glob `**/*.ts` for project structure
- Identify: RPC setup, existing ATA logic, entry point for ATA creation
- Task subagent (Grep/Read/WebFetch) if project has multiple packages to scan in parallel
### 2. Read references
- WebFetch the guide above — follow the TypeScript Client tab
- WebFetch skill.md — check for a dedicated skill and resources matching this task
- TaskCreate one todo per phase below to track progress
### 3. Clarify intention
- AskUserQuestion: what is the goal? (new feature, migrate existing SPL code, add alongside existing)
- AskUserQuestion: does the project already have ATA operations to extend, or is this greenfield?
- Summarize findings and wait for user confirmation before implementing
### 4. Create plan
- Based on steps 1–3, draft an implementation plan: which files to modify, what code to add, dependency changes
- Verify existing connection/signer setup is compatible with the cookbook prerequisites
- If anything is unclear or ambiguous, loop back to step 3 (AskUserQuestion)
- Present the plan to the user for approval before proceeding
### 5. Implement
- Add deps if missing: Bash `npm install @lightprotocol/compressed-token @lightprotocol/stateless.js`
- Follow the cookbook guide and the approved plan
- Write/Edit to create or modify files
- TaskUpdate to mark each step done
### 6. Verify
- Bash `tsc --noEmit`
- Bash run existing test suite if present
- TaskUpdate to mark complete
### Tools
- mcp__zkcompression__SearchLightProtocol("<query>") for API details
- mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "<q>") for architecture
- Task subagent with Grep/Read/WebFetch for parallel lookups
- TaskList to check remaining work
CreateAssociatedTokenAccount creates an on-chain ATA to store token balances of light, SPL, or Token 2022 mints.Compare to SPL:- Guide
- AI Prompt
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(())
}
Create ATA
Find the source code here.
- Action
- Instruction
Report incorrect code
Copy
Ask AI
use light_token_client::actions::{CreateAta, CreateMint};
use rust_client::setup_rpc_and_payer;
use solana_sdk::signer::Signer;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (mut rpc, payer) = setup_rpc_and_payer().await;
// Create mint
let (_signature, mint) = CreateMint {
decimals: 9,
freeze_authority: None,
token_metadata: None,
seed: None,
}
.execute(&mut rpc, &payer, &payer)
.await?;
// Create associated token account
let (_signature, associated_token_account) = CreateAta {
mint,
owner: payer.pubkey(),
idempotent: true,
}
.execute(&mut rpc, &payer)
.await?;
println!("Associated token account: {associated_token_account}");
Ok(())
}
Report incorrect code
Copy
Ask AI
use light_client::rpc::Rpc;
use light_token::instruction::{get_associated_token_address, CreateAssociatedTokenAccount};
use rust_client::{setup_spl_mint_context, SplMintContext};
use solana_sdk::{signature::Keypair, signer::Signer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// You can use Light, SPL, or Token-2022 mints to create a Light associated token account.
let SplMintContext {
mut rpc,
payer,
mint,
} = setup_spl_mint_context().await;
let owner = Keypair::new();
let create_associated_token_account_instruction =
CreateAssociatedTokenAccount::new(payer.pubkey(), owner.pubkey(), mint).instruction()?;
let sig = rpc
.create_and_send_transaction(&[create_associated_token_account_instruction], &payer.pubkey(), &[&payer])
.await?;
let associated_token_account = get_associated_token_address(&owner.pubkey(), &mint);
let data = rpc.get_account(associated_token_account).await?;
println!("Associated token account: {associated_token_account} exists: {} Tx: {sig}", data.is_some());
Ok(())
}
Create rent-free associated token account
Report incorrect code
Copy
Ask AI
---
description: Create rent-free associated token account
allowed-tools: Bash, Read, Write, Edit, Glob, Grep, WebFetch, AskUserQuestion, Task, TaskCreate, TaskGet, TaskList, TaskUpdate, TaskOutput, mcp__deepwiki, mcp__zkcompression
---
## Create rent-free associated token account
Context:
- Guide: https://zkcompression.com/light-token/cookbook/create-ata
- Skills and resources index: https://zkcompression.com/skill.md
- SPL to Light reference: https://zkcompression.com/api-reference/solana-to-light-comparison
- Crates: light-token-client (actions), light-token (instructions), light-client (RPC)
SPL equivalent: spl_associated_token_account::create → Light Token: CreateAta
### 1. Index project
- Grep `light_token::|light_token_client::|solana_sdk|Keypair|async|CreateAta|create_associated_token_account` across src/
- Glob `**/*.rs` for project structure
- Identify: RPC setup, existing token ops, entry point for ATA creation
- Check Cargo.toml for existing light-* dependencies and solana-sdk version
- Task subagent (Grep/Read/WebFetch) if project has multiple crates to scan in parallel
### 2. Read references
- WebFetch the guide above — follow the Rust Client tab
- WebFetch skill.md — check for a dedicated skill and resources matching this task
- TaskCreate one todo per phase below to track progress
### 3. Clarify intention
- AskUserQuestion: what is the goal? (new feature, migrate existing SPL code, add alongside existing)
- AskUserQuestion: does the project already have ATA operations to extend, or is this greenfield?
- AskUserQuestion: action-level API (high-level, fewer lines) or instruction-level API (low-level, full control)?
- Summarize findings and wait for user confirmation before implementing
### 4. Create plan
- Based on steps 1–3, draft an implementation plan: which files to modify, what code to add, dependency changes
- Verify existing Rpc/signer setup is compatible with the cookbook prerequisites (light_client::rpc::Rpc, solana_sdk::signature::Keypair)
- If anything is unclear or ambiguous, loop back to step 3 (AskUserQuestion)
- Present the plan to the user for approval before proceeding
### 5. Implement
- Add deps if missing: Bash `cargo add light-token-client light-token light-client --features light-client/v2`
- Follow the cookbook guide and the approved plan
- Write/Edit to create or modify files
- TaskUpdate to mark each step done
### 6. Verify
- Bash `cargo check`
- Bash `cargo test` if tests exist
- TaskUpdate to mark complete
### Tools
- mcp__zkcompression__SearchLightProtocol("<query>") for API details
- mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "<q>") for architecture
- Task subagent with Grep/Read/WebFetch for parallel lookups
- TaskList to check remaining work
- CPI
- Anchor Macros
- Guide
- AI Prompt
Compare to SPL:
Build Account Infos and CPI the Light Token Program
- Pass ATA accounts and call
.rent_free()with rent config accounts. - Use
invokeorinvoke_signed:- When the
payeris an external wallet, useinvoke. - When the
payeris a PDA, useinvoke_signedwith its seeds.
- When the
The light-ATA address is derived from
[owner, light_token_program_id, mint].
Unlike Light Token accounts, owner and mint are passed as accounts, not in
instruction data.- invoke (External signer)
- invoke_signed (PDA signer)
Report incorrect code
Copy
Ask AI
use light_token::instruction::CreateAssociatedAccountCpi;
CreateAssociatedAccountCpi {
payer: payer.clone(),
owner: owner.clone(),
mint: mint.clone(),
ata: associated_token_account.clone(),
bump,
}
.rent_free(
compressible_config.clone(),
rent_sponsor.clone(),
system_program.clone(),
)
.invoke()
Report incorrect code
Copy
Ask AI
use light_token::instruction::CreateAssociatedAccountCpi;
let signer_seeds: &[&[u8]] = &[ATA_SEED, &[authority_bump]];
CreateAssociatedAccountCpi {
payer: payer.clone(),
owner: owner.clone(),
mint: mint.clone(),
ata: associated_token_account.clone(),
bump,
}
.rent_free(
compressible_config.clone(),
rent_sponsor.clone(),
system_program.clone(),
)
.invoke_signed(&[signer_seeds])
| Owner | - |
|
| Mint | - |
|
| Payer | signer, mutable |
|
| light-ATA Account | mutable |
|
| - | Solana System Program. Required for CPI to create the on-chain account. | |
| Bump | u8 | The PDA bump seed for the light-ATA address derivation. |
| Idempotent | bool |
|
Full Code Example
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::CreateAssociatedAccountCpi;
declare_id!("35MukgdfpNUbPMhTmEk63ECV8vjgpNVFRH9nP8ovMN58");
#[program]
pub mod light_token_anchor_create_associated_token_account {
use super::*;
pub fn create_associated_token_account(ctx: Context<CreateAssociatedTokenAccountAccounts>, bump: u8, idempotent: bool) -> Result<()> {
let cpi = CreateAssociatedAccountCpi {
payer: ctx.accounts.payer.to_account_info(),
owner: ctx.accounts.owner.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
ata: ctx.accounts.associated_token_account.to_account_info(),
bump,
};
if idempotent {
cpi.idempotent().rent_free(
ctx.accounts.compressible_config.to_account_info(),
ctx.accounts.rent_sponsor.to_account_info(),
ctx.accounts.system_program.to_account_info(),
)
} else {
cpi.rent_free(
ctx.accounts.compressible_config.to_account_info(),
ctx.accounts.rent_sponsor.to_account_info(),
ctx.accounts.system_program.to_account_info(),
)
}
.invoke()?;
Ok(())
}
}
#[derive(Accounts)]
pub struct CreateAssociatedTokenAccountAccounts<'info> {
/// CHECK: Light token program for CPI
pub light_token_program: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub owner: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
pub mint: AccountInfo<'info>,
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub associated_token_account: AccountInfo<'info>,
pub system_program: Program<'info, System>,
/// CHECK: Validated by light-token CPI
pub compressible_config: AccountInfo<'info>,
/// CHECK: Validated by light-token CPI
#[account(mut)]
pub rent_sponsor: AccountInfo<'info>,
}
Add create-ATA CPI to an Anchor program
Report incorrect code
Copy
Ask AI
---
description: Add create-ATA CPI to an Anchor program
allowed-tools: Bash, Read, Write, Edit, Glob, Grep, WebFetch, AskUserQuestion, Task, TaskCreate, TaskGet, TaskList, TaskUpdate, TaskOutput, mcp__deepwiki, mcp__zkcompression
---
## Add create-ATA CPI to an Anchor program
Context:
- Guide: https://zkcompression.com/light-token/cookbook/create-ata
- Skills and resources index: https://zkcompression.com/skill.md
- SPL to Light reference: https://zkcompression.com/api-reference/solana-to-light-comparison
- Crate: light-token (CreateAssociatedAccountCpi)
- Example: https://github.com/Lightprotocol/examples-light-token/tree/main/programs/anchor/basic-instructions/create-associated-token-account
Key CPI struct: `light_token::instruction::CreateAssociatedAccountCpi`
### 1. Index project
- Grep `declare_id|#\[program\]|anchor_lang|Account<|Pubkey|invoke|ata|associated|owner|mint` across src/
- Glob `**/*.rs` and `**/Cargo.toml` for project structure
- Identify: program ID, existing instructions, account structs, ATA derivation
- Read Cargo.toml — note existing dependencies and framework version
- Task subagent (Grep/Read/WebFetch) if project has multiple crates to scan in parallel
### 2. Read references
- WebFetch the guide above — review the CPI tab under Program: ATA creation with .rent_free() chain
- WebFetch skill.md — check for a dedicated skill and resources matching this task
- TaskCreate one todo per phase below to track progress
### 3. Clarify intention
- AskUserQuestion: what is the goal? (add create-ATA to existing program, new program from scratch, migrate from SPL create_associated_token_account)
- AskUserQuestion: should the payer be an external signer or a PDA? (determines invoke vs invoke_signed)
- Summarize findings and wait for user confirmation before implementing
### 4. Create plan
- Based on steps 1–3, draft an implementation plan: which files to modify, what code to add, dependency changes
- Follow the guide's step order: Build CreateAssociatedAccountCpi → .rent_free() → .invoke() or .invoke_signed()
- If anything is unclear or ambiguous, loop back to step 3 (AskUserQuestion)
- Present the plan to the user for approval before proceeding
### 5. Implement
- Add deps if missing: Bash `cargo add light-token anchor-lang@0.31`
- Follow the guide and the approved plan
- Write/Edit to create or modify files
- TaskUpdate to mark each step done
### 6. Verify
- Bash `anchor build`
- Bash `anchor test` if tests exist
- TaskUpdate to mark complete
### Tools
- mcp__zkcompression__SearchLightProtocol("<query>") for API details
- mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "<q>") for architecture
- Task subagent with Grep/Read/WebFetch for parallel lookups
- TaskList to check remaining work
- Guide
- AI Prompt
Compare to SPL:
Dependencies
Report incorrect code
Copy
Ask AI
[dependencies]
light-sdk = { version = "0.18.0", features = ["anchor", "v2", "cpi-context"] }
light-sdk-macros = "0.18.0"
light-compressible = "0.1.0"
anchor-lang = "0.31"
Program
Add#[light_program] above #[program]:Report incorrect code
Copy
Ask AI
use light_sdk_macros::light_program;
#[light_program]
#[program]
pub mod light_token_macro_create_ata {
use super::*;
pub fn create_ata<'info>(
ctx: Context<'_, '_, '_, 'info, CreateAta<'info>>,
params: CreateAtaParams,
) -> Result<()> {
Ok(())
}
}
Accounts struct
DeriveLightAccounts on your Accounts struct and add #[light_account(...)] next to #[account(...)].Report incorrect code
Copy
Ask AI
/// CHECK: Validated by light-token CPI
#[account(mut)]
#[light_account(
init,
associated_token::authority = ata_owner,
associated_token::mint = ata_mint,
associated_token::bump = params.ata_bump
)]
pub ata: UncheckedAccount<'info>,
Full code example
View the source code and full example with shared test utilities.
Report incorrect code
Copy
Ask AI
#![allow(deprecated)]
use anchor_lang::prelude::*;
use light_compressible::CreateAccountsProof;
use light_sdk::derive_light_cpi_signer;
use light_sdk_macros::{light_program, LightAccounts};
use light_sdk_types::{CpiSigner, LIGHT_TOKEN_PROGRAM_ID};
use light_token::instruction::{COMPRESSIBLE_CONFIG_V1, RENT_SPONSOR as LIGHT_TOKEN_RENT_SPONSOR};
declare_id!("CLsn9MTFv97oMTsujRoQAw1u2rSm2HnKtGuWUbbc8Jfn");
pub const LIGHT_CPI_SIGNER: CpiSigner =
derive_light_cpi_signer!("CLsn9MTFv97oMTsujRoQAw1u2rSm2HnKtGuWUbbc8Jfn");
#[light_program]
#[program]
pub mod light_token_macro_create_associated_token_account {
use super::*;
#[allow(unused_variables)]
pub fn create_associated_token_account<'info>(
ctx: Context<'_, '_, '_, 'info, CreateAssociatedTokenAccount<'info>>,
params: CreateAssociatedTokenAccountParams,
) -> Result<()> {
Ok(())
}
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct CreateAssociatedTokenAccountParams {
pub create_accounts_proof: CreateAccountsProof,
pub associated_token_account_bump: u8,
}
#[derive(Accounts, LightAccounts)]
#[instruction(params: CreateAssociatedTokenAccountParams)]
pub struct CreateAssociatedTokenAccount<'info> {
#[account(mut)]
pub fee_payer: Signer<'info>,
/// CHECK: Token mint for the associated token account
pub associated_token_account_mint: AccountInfo<'info>,
/// CHECK: Owner of the associated token account
pub associated_token_account_owner: AccountInfo<'info>,
/// CHECK: Validated by light_account macro
#[account(mut)]
#[light_account(init, associated_token::authority = associated_token_account_owner, associated_token::mint = associated_token_account_mint, associated_token::bump = params.associated_token_account_bump)]
pub associated_token_account: UncheckedAccount<'info>,
/// CHECK: Validated by address constraint
#[account(address = COMPRESSIBLE_CONFIG_V1)]
pub light_token_compressible_config: AccountInfo<'info>,
/// CHECK: Validated by address constraint
#[account(mut, address = LIGHT_TOKEN_RENT_SPONSOR)]
pub light_token_rent_sponsor: AccountInfo<'info>,
/// CHECK: Light Token program for CPI
#[account(address = LIGHT_TOKEN_PROGRAM_ID.into())]
pub light_token_program: AccountInfo<'info>,
pub system_program: Program<'info, System>,
}
Create a rent-free ATA with Anchor macros
Report incorrect code
Copy
Ask AI
---
description: Create a rent-free ATA with Anchor macros
allowed-tools: Bash, Read, Write, Edit, Glob, Grep, WebFetch, AskUserQuestion, Task, TaskCreate, TaskGet, TaskList, TaskUpdate, TaskOutput, mcp__deepwiki, mcp__zkcompression
---
## Create a rent-free ATA with Anchor macros
Context:
- Guide: https://zkcompression.com/light-token/cookbook/create-ata
- Skills and resources index: https://zkcompression.com/skill.md
- SPL to Light reference: https://zkcompression.com/api-reference/solana-to-light-comparison
- Crates: light-sdk, light-sdk-macros, light-compressible, anchor-lang
- Example: https://github.com/Lightprotocol/examples-light-token/tree/main/programs/anchor/basic-macros/create-associated-token-account
Key macros: `#[light_program]`, `LightAccounts`, `#[light_account(init, associated_token::...)]`
### 1. Index project
- Grep `#\[program\]|anchor_lang|Account<|Accounts|seeds|init|payer|ata|associated` across src/
- Glob `**/*.rs` and `**/Cargo.toml` for project structure
- Identify: existing program module, account structs, ATA patterns
- Read Cargo.toml — note existing dependencies and framework version
- Task subagent (Grep/Read/WebFetch) if project has multiple crates to scan in parallel
### 2. Read references
- WebFetch the guide above — review the Anchor Macros tab under Program
- WebFetch skill.md — check for a dedicated skill and resources matching this task
- TaskCreate one todo per phase below to track progress
### 3. Clarify intention
- AskUserQuestion: what is the goal? (new program from scratch, add rent-free ATA to existing program, migrate from SPL create_associated_token_account)
- Summarize findings and wait for user confirmation before implementing
### 4. Create plan
- Based on steps 1–3, draft an implementation plan
- Follow the guide's step order: Dependencies → Program Module (#[light_program]) → Accounts Struct (#[light_account(init, associated_token::...)])
- If anything is unclear or ambiguous, loop back to step 3 (AskUserQuestion)
- Present the plan to the user for approval before proceeding
### 5. Implement
- Add deps if missing: Bash `cargo add light-sdk@0.18 --features anchor,v2,cpi-context` and `cargo add light-sdk-macros@0.18 light-compressible@0.1 anchor-lang@0.31`
- Follow the guide and the approved plan
- Write/Edit to create or modify files
- TaskUpdate to mark each step done
### 6. Verify
- Bash `anchor build`
- Bash `anchor test` if tests exist
- TaskUpdate to mark complete
### Tools
- mcp__zkcompression__SearchLightProtocol("<query>") for API details
- mcp__deepwiki__ask_question("Lightprotocol/light-protocol", "<q>") for architecture
- Task subagent with Grep/Read/WebFetch for parallel lookups
- TaskList to check remaining work