Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
Every Solana transaction pays a tiny base fee (5,000 lamports per signature), an optional priority fee (micro-lamports per CU), and accounts must hold a rent-exempt SOL balance to persist. The model is much cheaper than Ethereum but more complex — you pay per signature, per CU consumed, AND must maintain SOL deposits per account.
Fee breakdown for a typical swap.
ComputeBudgetProgram::set_compute_unit_price(10000) instruction and observe the priority fee added.Use these three in order. Each builds on the one before.
In one paragraph, explain Solana's fee model: base, priority, rent.
Walk me through how priority fees are calculated — micro-lamports per CU * CU limit.
Given a high-throughput protocol making millions of small swaps, design the fee strategy that minimizes user cost while still landing during congestion.
// Per-tx base fee:
const BASE_FEE_PER_SIG: u64 = 5_000; // lamports per signature
// Most txs have 1-2 signatures:
// base = 5,000 * 1 = 5,000 lamports = 0.000005 SOL ($0.0007 at $140/SOL)
// Priority fee (optional, but required when congested):
// ComputeBudgetProgram::set_compute_unit_limit(200_000) — cap CUs to use
// ComputeBudgetProgram::set_compute_unit_price(1_000) — price per CU in micro-lamports
// At 200,000 CU * 1,000 micro-lamports/CU * 1e-6 = 200,000 lamports priority fee
// = 0.0002 SOL = $0.028 at $140/SOL
// Total swap cost in modest congestion:
// base + priority = 5,000 + 200,000 = 205,000 lamports ≈ $0.029
// Rent:
// New accounts must hold a rent-exempt deposit
// formula: (128 + size_bytes) * 6960 lamports per byte-year
// For a 165-byte token account: (128 + 165) * 6960 = ~2.04e6 lamports
// = 0.002 SOL = ~$0.28 at $140/SOL
// This is RETURNED when the account is closed
// Net: most txs cost <$0.05, including priority during congestion.