Using Anchor for Solana development? Here's how LUMOS supercharges your workflow by generating Anchor-compatible code from schemas.
LUMOS + Anchor: Better Together
LUMOS complements Anchor, it doesn't replace it.
Think of it this way:
- Anchor = The framework that runs your Solana program
- LUMOS = The tool that generates Anchor code from a schema
Why Use Both?
| Without LUMOS | With LUMOS |
|---|---|
| Manually write Rust structs | Define once in .lumos schema |
| Manually write TypeScript types | Auto-generate TypeScript |
| Hope Rust ↔ TS stay in sync | Guaranteed sync (same source) |
| Calculate account space by hand | Auto-calculated LEN constants |
| Write IDL manually or extract | Auto-generate IDL from schema |
Quick Start
1. Define Schema
// game.lumos
#[solana]
#[account]
struct GameConfig {
authority: PublicKey,
max_players: u32,
entry_fee: u64,
prize_pool: u64,
}
#[solana]
#[account]
struct Player {
wallet: PublicKey,
game: PublicKey,
score: u64,
joined_at: i64,
}
#[solana]
enum GameInstruction {
Initialize { max_players: u32, entry_fee: u64 },
JoinGame,
UpdateScore { score: u64 },
ClaimPrize,
}
2. Generate Anchor Program
lumos anchor generate game.lumos \
--name game_program \
--typescript
3. Generated Structure
game_program/
├── programs/game_program/
│ ├── src/
│ │ ├── lib.rs # Program entry point
│ │ └── state.rs # Account structs
│ └── Cargo.toml
├── target/idl/
│ └── game_program.json # Anchor IDL
└── client/
└── game_program.ts # TypeScript client
CLI Commands
Generate Complete Program
lumos anchor generate <SCHEMA> [OPTIONS]
Options:
-o, --output <DIR> Output directory
-n, --name <NAME> Program name
-V, --version <VER> Program version (default: 0.1.0)
-a, --address <ADDR> Program address
--typescript Generate TypeScript client
--dry-run Preview without writing
Example:
lumos anchor generate game.lumos \
--name my_game \
--version 1.0.0 \
--address "Game111111111111111111111111111111111111111" \
--typescript
Generate Only IDL
lumos anchor idl game.lumos --pretty -o target/idl/game.json
Calculate Account Space
lumos anchor space game.lumos --format rust
Output:
impl GameConfig {
pub const LEN: usize = 8 + 32 + 4 + 8 + 8; // 60 bytes
}
impl Player {
pub const LEN: usize = 8 + 32 + 32 + 8 + 8; // 88 bytes
}
Generated Code Example
Rust (state.rs)
use anchor_lang::prelude::*;
#[account]
pub struct GameConfig {
pub authority: Pubkey,
pub max_players: u32,
pub entry_fee: u64,
pub prize_pool: u64,
}
impl GameConfig {
pub const LEN: usize = 8 + 32 + 4 + 8 + 8;
}
#[account]
pub struct Player {
pub wallet: Pubkey,
pub game: Pubkey,
pub score: u64,
pub joined_at: i64,
}
impl Player {
pub const LEN: usize = 8 + 32 + 32 + 8 + 8;
}
TypeScript (game_program.ts)
import { PublicKey } from '@solana/web3.js';
import * as borsh from '@coral-xyz/borsh';
export interface GameConfig {
authority: PublicKey;
maxPlayers: number;
entryFee: number;
prizePool: number;
}
export const GameConfigSchema = borsh.struct([
borsh.publicKey('authority'),
borsh.u32('maxPlayers'),
borsh.u64('entryFee'),
borsh.u64('prizePool'),
]);
When to Use LUMOS vs Anchor Alone
| Scenario | Recommendation |
|---|---|
| Starting a new Anchor project | ✅ Use LUMOS |
| Existing project, want type sync | ✅ Use LUMOS |
| Simple program, few account types | ⚠️ Either works |
| Complex program, many shared types | ✅ Use LUMOS |
| Team with mixed Rust/TS developers | ✅ Use LUMOS |
Bottom line: If you're writing TypeScript clients that interact with your Anchor program, LUMOS saves you from maintaining duplicate type definitions.
Get Started
cargo install lumos-cli
lumos anchor generate schema.lumos --typescript
- Documentation: https://docs.lumos-lang.org/frameworks/anchor/
- GitHub: https://github.com/getlumos/lumos
Questions? Drop them below!
Top comments (0)