5분 안에 LUMOS: 첫 번째 Solana 스키마

발행: (2025년 12월 18일 오전 08:12 GMT+9)
2 min read
원문: Dev.to

Source: Dev.to

LUMOS를 5분 안에 시작하기: 첫 번째 Solana 스키마 표지 이미지

Solana 앱에 타입‑안전한 Rust + TypeScript가 필요하신가요? 정확히 5분 안에 작동하는 스키마를 만들 수 있도록 도와드릴게요.

Minute 1: Installation

cargo install lumos-cli

Verify:

lumos --version
# Output: lumos-cli 0.1.0

No Rust? Use npm instead:

npx @getlumos/cli --version

Minute 2: Initialize Project

lumos init my-game
cd my-game

This creates:

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

Minute 3: Write Your Schema

Open schema.lumos and add:

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

#[solana]
struct MatchResult {
    player: PublicKey,
    opponent: Option,
    score: u64,
    timestamp: i64,
}

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 – Optional value

Minute 4: Generate Code

lumos generate schema.lumos

Output

  Generating Rust code
       Wrote ./generated.rs
  Generating TypeScript code
       Wrote ./generated.ts
    Finished generated 2 type definitions

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,
}

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'),
]);

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) -> Result {
        let player = &mut ctx.accounts.player;
        player.wallet = *ctx.accounts.user.key;
        player.level = 1;
        player.experience = 0;
        Ok(())
    }
}

TypeScript Client

import { PlayerAccount, PlayerAccountBorshSchema } from './generated';
import { PublicKey, Connection } from '@solana/web3.js';

async function getPlayer(pubkey: PublicKey, connection: Connection): Promise {
  const accountInfo = await connection.getAccountInfo(pubkey);
  if (!accountInfo) throw new Error('Account not found');
  return PlayerAccountBorshSchema.deserialize(accountInfo.data);
}

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

Back to Blog

관련 글

더 보기 »

스마트 계약 초보자를 위한

소개 블록체인 개념을 배우는 것은 어려울 수 있지만, 스마트 계약을 이해하는 것은 그리 어려울 필요가 없습니다. 이 가이드는 스마트 계약의 기본을 소개합니다.