Complete Zig implementation of the Solana SDK, enabling Solana blockchain development in Zig.
This project provides a comprehensive, type-safe Zig SDK that mirrors the Rust solana-sdk crate, allowing developers to build Solana programs and clients using Zig's modern, memory-safe language.
- Complete Solana SDK Implementation - Full feature parity with Rust
solana-sdk - Native SBF Support - solana-zig compiles directly to Solana BPF target
- Type-Safe API - Zero-cost abstractions matching Rust SDK
- Two-Layer Architecture - Shared SDK types + Program SDK with syscalls
┌─────────────┐ ┌─────────────┐
│ Zig Code │───────────────────>│ Solana eBPF │
│ │ solana-zig │ (.so) │
└─────────────┘ └─────────────┘
solana-program-sdk-zig/
├── sdk/ # Shared SDK (no syscalls)
│ └── src/
│ ├── public_key.zig # PublicKey type (pure SHA256 PDA)
│ ├── hash.zig # Hash type
│ ├── signature.zig # Signature type
│ ├── keypair.zig # Keypair type
│ ├── instruction.zig # Instruction types (no CPI)
│ ├── bincode.zig # Bincode serialization
│ ├── borsh.zig # Borsh serialization
│ └── ...
├── src/ # Program SDK (with syscalls)
│ ├── public_key.zig # Re-exports SDK + syscall PDA
│ ├── instruction.zig # Re-exports SDK + CPI
│ ├── account.zig # Account types
│ ├── syscalls.zig # Solana syscalls
│ ├── entrypoint.zig # Program entrypoint
│ ├── log.zig # Logging
│ └── ...
├── program-test/ # Integration tests
└── build.zig
./install-solana-zig.sh
# Or set custom version
SOLANA_ZIG_VERSION=v1.52.0 ./install-solana-zig.shsolana-zig is a modified Zig compiler with native Solana SBF target support. It compiles directly to .so files without external linkers.
# Solana CLI
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"// src/main.zig
const sdk = @import("solana_program_sdk");
fn processInstruction(
program_id: *sdk.PublicKey,
accounts: []sdk.Account,
data: []const u8,
) sdk.ProgramResult {
sdk.log.sol_log("Hello from Zig!");
return .ok;
}
comptime {
sdk.entrypoint.define(processInstruction);
}# Build for Solana
./solana-zig/zig build -Dtarget=sbf-solanaconst sdk = @import("solana_sdk");
pub fn main() !void {
const pubkey = try sdk.PublicKey.fromBase58("11111111111111111111111111111112");
const keypair = sdk.Keypair.generate();
std.debug.print("Public key: {s}\n", .{pubkey.toBase58()});
}# Test Program SDK (285 tests)
./solana-zig/zig build test --summary all
# Test SDK only (105 tests)
cd sdk && ../solana-zig/zig build test --summary all
# Integration tests
./program-test/test.shFor off-chain BN254 elliptic curve operations:
git submodule update --init vendor/mcl
./solana-zig/zig build test -Dwith-mclMCL is optional. On-chain programs use Solana's native syscalls (sol_alt_bn128_*).
See ROADMAP.md for current implementation status.
MIT