Write Solana programs in Gleam - the friendly functional language that compiles to Solana BPF bytecode.
- Type-safe - Catch errors at compile time
- Fast to learn - Simple, consistent syntax
- Functional - Immutable data, pure functions
- Reliable - No null, no exceptions
- Well-loved - Consistently ranked as most loved language
# Install Gleam
curl -fsSL https://gleam.run/install.sh | sh
# Clone and build
git clone https://github.com/openSVM/gleam-sbpf.git
cd gleam-sbpf
gleam build
# Run your first program
gleam runNew to Solana development? → Start with the Onboarding Guide
Test your Solana programs with GleamSVM, a Gleam-native VM with 10x more security checks than LiteSVM!
import gleamsvm/vm
import gleamsvm/security
// Create VM with 20+ security validations
let vm_state = vm.new()
let vm_with_account = vm.airdrop(vm_state, 123, 1_000_000_000)Build Solana programs with an Anchor-like framework for Gleam! Get automatic account validation, instruction dispatch, and error handling.
import anchor.{type Context, type ProgramResult, Success, Signer, Writable}
pub fn process_initialize(ctx: Context) -> ProgramResult(Int) {
case anchor.get_account(ctx, 0) {
Success(account) -> {
case anchor.validate_account(account, [Signer, Writable]) {
Success(_) -> Success(0) // Initialized!
Error(code, msg) -> Error(code, msg)
}
}
Error(code, msg) -> Error(code, msg)
}
}→ Anchor Quick Start | Full Anchor Docs
Test your programs 100x faster than the Solana test validator with in-memory testing:
scripts/test_litesvm.sh📚 Complete Documentation Index
- Onboarding Guide - Complete walkthrough for beginners (START HERE)
- Getting Started - Quick overview
- Gleam Guide - Learn the Gleam language
- Anchor Framework - Complete API reference
- Testing Guide - Unit & integration tests
- Best Practices - Write secure programs
- Solana BPF Guide - Deep dive into BPF
- Implementation Details - Compiler architecture
- CI/CD Setup - Automated testing & deployment
- Tokens: SPL-compatible tokens with mint, burn, transfer
- AMMs: Uniswap-style swaps, liquidity pools
- Lending: Collateralized loans, interest rates
- Staking: Lock tokens, earn rewards
- NFTs: Minting, marketplaces, royalties
- Derivatives: Options, futures, perpetuals
- Arbitrage: DEX arbitrage, flash loans
- Market Making: Bid/ask spreads, inventory management
- Grid Trading: Range-bound strategies
import compiler.{IntLiteral, Return}
Return(IntLiteral(42))Compiles to Solana BPF:
b7 00 00 00 2a 00 00 00 // MOV r0, 42
95 00 00 00 00 00 00 00 // EXIT
pub fn process_increment(ctx: Context, current: Int) -> ProgramResult(Int) {
case anchor.get_account(ctx, 0) {
Success(counter) -> {
case anchor.validate_account(counter, [Writable]) {
Success(_) -> Success(current + 1)
Error(code, msg) -> Error(code, msg)
}
}
Error(code, msg) -> Error(code, msg)
}
}See Counter Program and 25 Anchor Examples
gleam-sbpf/
├── src/ # Source code
│ ├── compiler.gleam # Expression compilation
│ ├── opcode.gleam # BPF opcode definitions (105+ opcodes)
│ ├── instruction.gleam # Instruction encoding
│ ├── elf.gleam # Solana BPF ELF generation
│ ├── anchor.gleam # Anchor-like framework
│ ├── counter.gleam # Counter program example
│ └── gleamsvm/ # GleamSVM testing VM
├── test/ # Test suite (64+ tests)
├── docs/ # Documentation
│ ├── guides/ # Getting started & tutorials
│ ├── testing/ # Testing documentation
│ ├── architecture/ # Technical deep dives
│ ├── reference/ # Best practices & tooling
│ └── releases/ # Release notes & summaries
├── scripts/ # Utility scripts
│ ├── test_litesvm.sh
│ ├── test_solana_tooling.sh
│ └── test_validator_deploy.sh
├── anchor_examples/ # 25+ Anchor framework examples
├── tutorials/ # 50+ DeFi tutorials
├── trading_bots/ # Trading bot examples
├── reference_implementations/ # Production-quality code
└── litesvm_tests/ # LiteSVM integration tests
- Complete BPF Support: All 105+ Solana BPF opcodes
- Solana Compatible: Generates valid
.sofiles for deployment - Type Safety: Leverages Gleam's type system for correctness
- Fast Testing: LiteSVM integration (100x faster than validator)
- Anchor Framework: Build programs like Rust's Anchor
- Security First: GleamSVM with 20+ security validations
- Comprehensive Tests: 64+ unit, integration, and end-to-end tests
gleam testExpected output: 64 passed, no failures
scripts/test_litesvm.shscripts/test_validator_deploy.shSee Testing Documentation for details.
- Gleam 1.13.0 or later
- Erlang/OTP 25 or later
- Rebar3
gleam buildgleam runThis generates example Solana BPF files: example1.so, example2.so
file example1.so
# Output: ELF 64-bit LSB shared object, eBPF, version 1 (SYSV)
readelf -h example1.so
# Shows: Type: DYN (Shared object), Flags: 0x2 (SBPF v2)Deploy compiled programs to Solana:
# Configure for devnet
solana config set --url https://api.devnet.solana.com
# Deploy program
solana program deploy example1.soSee Solana Tooling Guide for complete deployment documentation.
New to blockchain development? Follow this path:
- Onboarding Guide - Complete walkthrough (START HERE)
- Anchor Quick Start - Build with Anchor framework
- Getting Started - First program
- Simple Token Tutorial - First DeFi app
Ready for DeFi? Try these:
- Counter Program - Learn Anchor patterns
- Constant Product AMM - Build a DEX
- Simple Staking - Create yield farming
We welcome contributions! See CONTRIBUTING.md for guidelines.
Ways to contribute:
- 🐛 Report bugs via GitHub Issues
- 💡 Request features via GitHub Discussions
- 📝 Improve documentation
- 🔧 Submit pull requests
- 📚 Create tutorials and examples
Please read our Code of Conduct before contributing.
- GitHub Discussions - Ask questions, share projects
- Gleam Discord - Gleam language community
- Solana Discord - Solana development
- 64+ tests: Unit, integration, Anchor, LiteSVM
- 105+ BPF opcodes: Complete instruction set
- 50+ tutorials: Comprehensive learning materials
- 25+ Anchor examples: Framework demonstrations
- 100x faster testing: LiteSVM integration
- Production-ready: Full Solana compatibility
Found a security issue? Please email security@gleam-sbpf.dev (or open a private security advisory).
For best practices, see our Security Guide.
This project is licensed under the MIT License - see the LICENSE file for details.
- Gleam team - For creating an excellent functional programming language
- Solana team - For the robust BPF infrastructure and developer tools
- Community contributors - For tutorials, bug reports, and feature improvements
Questions? Visit GitHub Discussions
Ready to build? Start with the Onboarding Guide
This implementation bears strength in discipline.