@lightprotocol/stateless.js is the core JavaScript SDK for building applications on Light Protocol. It provides a comprehensive API for working with compressed accounts, managing state trees, and interacting with the Light system program.
The SDK provides a custom RPC client that extends Solana’s Connection with compression-specific methods:
import { createRpc } from '@lightprotocol/stateless.js';// Connect to local test validatorconst rpc = createRpc();// Or connect to a custom endpointconst rpc = createRpc( 'https://devnet.helius-rpc.com', 'https://devnet.helius-rpc.com');
Compressed accounts are stored in Merkle trees. The SDK automatically manages tree selection:
import { selectStateTreeInfo } from '@lightprotocol/stateless.js';// Get available state treesconst stateTreeInfos = await rpc.getStateTreeInfos();// Select an appropriate treeconst stateTree = selectStateTreeInfo(stateTreeInfos);// Use the tree for operationsawait compress( rpc, payer, 10_000_000, recipient, stateTree // Optional: specify output tree);
The SDK is written in TypeScript with full type definitions:
import type { CompressedAccountWithMerkleContext, ValidityProofWithContext, TreeInfo, Rpc,} from '@lightprotocol/stateless.js';// All types are exported for use in your applicationconst account: CompressedAccountWithMerkleContext = { hash: bn(accountHash), treeInfo: stateTree, leafIndex: 42, owner: owner.publicKey, lamports: bn(1_000_000), address: null, data: null,};