DEV Community

Cover image for LUMOS in 5 Minutes: Your First Solana Schema
RECTOR SOL for LUMOS

Posted on • Originally published at docs.lumos-lang.org

LUMOS in 5 Minutes: Your First Solana Schema

Want type-safe Rust + TypeScript for your Solana app? Let's get you from zero to working schema in exactly 5 minutes.

Minute 1: Installation

cargo install lumos-cli
Enter fullscreen mode Exit fullscreen mode

Verify:

lumos --version
# Output: lumos-cli 0.1.0
Enter fullscreen mode Exit fullscreen mode

No Rust? Use npm instead:

npx @getlumos/cli --version
Enter fullscreen mode Exit fullscreen mode

Minute 2: Initialize Project

lumos init my-game
cd my-game
Enter fullscreen mode Exit fullscreen mode

This creates:

my-game/
├── schema.lumos    ← Your schema definition
├── lumos.toml      ← Configuration
└── README.md       ← Getting started guide
Enter fullscreen mode Exit fullscreen mode

Minute 3: Write Your Schema

Open schema.lumos:

#[solana]
#[account]
struct PlayerAccount {
    wallet: PublicKey,
    level: u16,
    experience: u64,
    equipped_items: [PublicKey],
}

#[solana]
struct MatchResult {
    player: PublicKey,
    opponent: Option<PublicKey>,
    score: u64,
    timestamp: i64,
}
Enter fullscreen mode Exit fullscreen mode

What's happening:

  • #[solana] - Solana-specific type
  • #[account] - Anchor account (uses Anchor macros)
  • PublicKey - Maps to Pubkey in Rust, PublicKey in TS
  • [PublicKey] - Vector/array
  • Option<T> - Optional value

Minute 4: Generate Code

lumos generate schema.lumos
Enter fullscreen mode Exit fullscreen mode

Output:

  Generating Rust code
       Wrote ./generated.rs
  Generating TypeScript code
       Wrote ./generated.ts
    Finished generated 2 type definitions
Enter fullscreen mode Exit fullscreen mode

Rust Output (generated.rs)

use anchor_lang::prelude::*;

#[account]
pub struct PlayerAccount {
    pub wallet: Pubkey,
    pub level: u16,
    pub experience: u64,
    pub equipped_items: Vec<Pubkey>,
}
Enter fullscreen mode Exit fullscreen mode

TypeScript Output (generated.ts)

import { PublicKey } from '@solana/web3.js';
import * as borsh from '@coral-xyz/borsh';

export interface PlayerAccount {
  wallet: PublicKey;
  level: number;
  experience: number;
  equipped_items: PublicKey[];
}

export const PlayerAccountBorshSchema = borsh.struct([
  borsh.publicKey('wallet'),
  borsh.u16('level'),
  borsh.u64('experience'),
  borsh.vec(borsh.publicKey(), 'equipped_items'),
]);
Enter fullscreen mode Exit fullscreen mode

Minute 5: Use in Your Project

Anchor Program

mod generated;
use generated::*;

#[program]
pub mod my_game {
    use super::*;

    pub fn create_player(ctx: Context<CreatePlayer>) -> Result<()> {
        let player = &mut ctx.accounts.player;
        player.wallet = *ctx.accounts.user.key;
        player.level = 1;
        player.experience = 0;
        Ok(())
    }
}
Enter fullscreen mode Exit fullscreen mode

TypeScript Client

import { PlayerAccount, PlayerAccountBorshSchema } from './generated';

async function getPlayer(pubkey: PublicKey): Promise<PlayerAccount> {
  const accountInfo = await connection.getAccountInfo(pubkey);
  return PlayerAccountBorshSchema.deserialize(accountInfo.data);
}
Enter fullscreen mode Exit fullscreen mode

You're Done!

In 5 minutes you:

✅ Installed LUMOS CLI
✅ Created your first .lumos schema
✅ Generated type-safe Rust + TypeScript
✅ Learned the complete workflow

What you got:

  • Type-safe schemas shared between languages
  • Automatic Borsh serialization
  • Zero manual boilerplate
  • Anchor-ready code

Next Steps


Questions? Drop them below!

Top comments (0)