30 essential Rust snippets for Solana, Near, and Polkadot smart contract development. From ownership to anchor.
You already have crypto in your wallet. Just send $1.
5 categories · 30 copy-paste ready snippets
Full pack has 30 snippets. Here's a taste.
// Transfer SOL from one account to another — ownership moves pub fn transfer_sol( ctx: Context<TransferSol>, amount: u64, ) -> Result<()> { let from = &mut ctx.accounts.from; // borrow mut let to = &mut ctx.accounts.to; // borrow mut **from.try_borrow_mut_lamports()? -= amount; **to.try_borrow_mut_lamports()? += amount; Ok(()) }
// Solana account data layout using Borsh #[derive(BorshSerialize, BorshDeserialize, Debug)] pub struct TaskAccount { pub discriminator: [u8; 8], // anchor discriminator pub author: Pubkey, pub title: String, pub completed: bool, pub created_at: i64, }
// Anchor error codes with #[msg] #[error_code] pub enum TaskError { #[msg("Task is already completed")] AlreadyCompleted, #[msg("Deadline has passed")] DeadlinePassed, #[msg("Unauthorized: not the task author")] Unauthorized, }
// Anchor program for a simple counter #[program] pub mod counter { use super::*; #[instruction] pub fn increment(ctx: Context<Increment>) -> Result<()> { ctx.accounts.counter.count += 1; Ok(()) } #[derive(Accounts)] pub struct Increment<'info> { #[account(mut, seeds = [b"counter", user.key().as_ref()], bump)] pub counter: Account<'info, Counter>, #[account(mut)] pub user: Signer<'info>, } }
// Cross-program invocation without Anchor pub fn invoke_transfer( from: &AccountInfo, to: &AccountInfo, amount: u64, ) -> Result<()> { let ix = Instruction { program_id: solana_program::system_program::ID, accounts: vec![ AccountMeta::new(from.key(), true), AccountMeta::new(to.key(), false), ], data: solana_program::system_instruction::transfer(&from.key(), &to.key(), amount).data, }; solana_program::program::invoke(&ix, &[from.clone(), to.clone()]) }
+ 25 more snippets in the full pack
Send $1 (or any amount) to the ETH address below. The PDF and GitHub repo link are delivered automatically within 1 minute. If you don't receive it, open an issue on GitHub.
This pack focuses on Web3-specific patterns — PDA derivation, CPI, account validation, Anchor macros, Near cross-contract calls. Even experienced Rust devs save hours.
Solana (Anchor + native BPF), Near (Rust SDK), and Polkadot (ink!). The snippets are chain-specific with cross-chain patterns where applicable.
It's $1. But yes — if the snippets don't help, send an email and you'll get a full refund in ETH.
Yes. Compatible with Anchor 0.30+, Solana 2.x, Near SDK 5.x, and ink! 5.x. Updated quarterly.
You already have crypto in your wallet. Just send $1.
Send ETH / USDT / SOL to
0x0D42B32D6E21F496082104BFC8d7213081474577
Delivery: PDF + GitHub private repo access within 1 min