light_sdk 0.1.0-beta.1
light_sdk: ^0.1.0-beta.1 copied to clipboard
Dart SDK for Light Protocol ZK Compression on Solana. Provides type-safe compressed account operations, compressed token transfers, and seamless integration with the Light Protocol compression infrastructure.
[Light Protocol Dart SDK]
Light Protocol SDK for Dart #
A Dart/Flutter SDK for Light Protocol ZK Compression on Solana.
The Story #
I was building a mobile app that needed cheap token transfers on Solana. When I discovered Light Protocol's ZK Compression (1000x cheaper!), I was excited—until I realized there was no Dart SDK. Only TypeScript and Rust.
So I ported it. This is a Dart implementation of @lightprotocol/stateless.js and @lightprotocol/compressed-token, built for Flutter developers who want to use ZK compression without leaving the Dart ecosystem.
What This SDK Does #
- Compress SOL → Store SOL in compressed accounts (way cheaper)
- Transfer Compressed SOL → Move compressed SOL between accounts
- Decompress SOL → Convert back to regular SOL when needed
- Compressed Tokens → Same operations for SPL tokens
Installation #
dependencies:
light_sdk:
git:
url: https://github.com/Lightprotocol/light-protocol.git
path: dart-light
Note: This package depends on the
solanapackage from espresso-cash.
Quick Start #
import 'package:light_sdk/light_sdk.dart';
import 'package:solana/solana.dart';
void main() async {
// Connect to RPC with compression API support
final rpc = Rpc.create(
'https://mainnet.helius-rpc.com?api-key=YOUR_KEY',
);
// Your wallet
final wallet = await Ed25519HDKeyPair.fromMnemonic('your mnemonic...');
// Compress 1 SOL
final signature = await compress(
rpc: rpc,
payer: wallet,
lamports: BigInt.from(1000000000),
toAddress: wallet.publicKey,
);
print('Compressed! Signature: $signature');
// Check compressed balance
final balance = await rpc.getCompressedBalanceByOwner(wallet.publicKey);
print('Compressed balance: $balance lamports');
// Transfer to someone
final recipient = Ed25519HDPublicKey.fromBase58('...');
await transfer(
rpc: rpc,
payer: wallet,
owner: wallet,
lamports: BigInt.from(100000),
toAddress: recipient,
);
}
API Overview #
High-Level Actions #
// Compress SOL
await compress(rpc: rpc, payer: wallet, lamports: amount, toAddress: recipient);
// Transfer compressed SOL
await transfer(rpc: rpc, payer: wallet, owner: wallet, lamports: amount, toAddress: recipient);
// Decompress back to regular SOL
await decompress(rpc: rpc, payer: wallet, lamports: amount, recipient: recipient);
RPC Methods #
// Get compressed accounts
final accounts = await rpc.getCompressedAccountsByOwner(owner);
// Get compressed balance
final balance = await rpc.getCompressedBalanceByOwner(owner);
// Get validity proof (needed for transactions)
final proof = await rpc.getValidityProof(hashes: [accountHash]);
// Get token balances
final tokens = await rpc.getCompressedTokenBalancesByOwner(owner);
Compressed Tokens #
// Create token pool (one-time setup per mint)
final poolInstruction = CompressedTokenProgram.createSplInterface(
payer: wallet.publicKey,
mint: mintPubkey,
);
// Mint compressed tokens
final mintInstruction = CompressedTokenProgram.mintTo(
payer: wallet.publicKey,
mint: mintPubkey,
authority: mintAuthority.publicKey,
amount: BigInt.from(1000000),
toPubkey: recipient,
outputStateTreeInfo: treeInfo,
);
// Transfer compressed tokens
final transferInstruction = CompressedTokenProgram.transfer(
payer: wallet.publicKey,
inputCompressedTokenAccounts: inputAccounts,
toAddress: recipient,
amount: BigInt.from(1000),
recentInputStateRootIndices: proof.rootIndices,
recentValidityProof: proof.compressedProof,
);
Examples #
Check out the example/ directory:
basic_usage.dart- Compress, transfer, and decompress SOLcompressed_tokens.dart- Working with compressed SPL tokensadvanced_usage.dart- Manual transaction building, validity proofsflutter_integration.dart- Patterns for Flutter apps
Requirements #
- Dart SDK ≥ 3.7.0
- An RPC endpoint with compression API support (e.g., Helius)
How It Works #
Light Protocol uses ZK compression to store account state in Merkle trees instead of on-chain accounts. This means:
- No rent - Compressed accounts don't pay rent
- Cheaper transactions - State changes are smaller
- Same security - Zero-knowledge proofs ensure validity
The trade-off is that you need an indexer (like Photon) to query compressed state. This SDK handles that automatically through the RPC layer.
Contributing #
Contributions welcome! Please read CONTRIBUTING.md first.
License #
Apache 2.0 - see LICENSE
Links #
Built with ☕ and frustration that there was no Dart SDK.