Solana Primitives
A lightweight Rust crate providing fundamental Solana blockchain primitives for constructing and submitting transactions without requiring the full Solana SDK.
Features
- Core Solana Types:
Pubkey,Signature,Instruction,Transaction,Message - Builder Pattern APIs: Fluent
TransactionBuilderandInstructionBuilderwith automatic account management - Instruction Data Builder: Type-safe
InstructionDataBuilderfor constructing instruction payloads - Program Helpers: Pre-built instructions for System, Token, and other common programs
- Program ID Utilities: Helper functions for common program IDs (System, Token, Token 2022, etc.)
- PDA Support: Program Derived Address generation and validation
- Error Handling: Comprehensive error types with detailed context messages
- Lightweight: Minimal dependencies for reduced bloat
Usage
Add this to your Cargo.toml:
[]
= "0.2.6"
Quick Start
use ;
Advanced Usage
Versioned (V0) Transactions with Lookup Tables
use ;
let fee_payer = new;
let recipient = new;
let looked_up = new;
let recent_blockhash = ;
let mut tx_builder = new;
tx_builder.add_instructions;
let address_lookup_tables = vec!;
let tx = tx_builder.build_v0?;
let wire_bytes = tx.serialize?;
Program Derived Addresses (PDAs)
use ;
let program_id = from_base58?;
let seeds = ;
let seed_refs: = seeds.iter.map.collect;
let = find_program_address?;
println!;
Error Handling
The crate provides detailed error context:
use ;
// Error message: "Invalid public key: failed to decode base58: invalid"
Available Program Helpers
The crate includes pre-built instruction constructors for common Solana programs:
- System Program:
transfer,create_account,allocate, etc. - Token Program:
transfer,transfer_checked,mint_to,burn, etc. - Associated Token Program:
create_associated_token_account - Compute Budget Program:
set_compute_unit_limit,set_compute_unit_price
Program ID helpers are available for easy access:
use ;
Examples
See solana-primitives/examples/ for complete working examples:
basic- Basic transaction constructiondecode_tx- Transaction deserialization
Run examples with: