Code Snippets

Annotated, copy-pasteable blockchain code examples in Solidity, Vyper, Rust, and JavaScript.

18 snippets

solidityethereumintermediate

ERC-721 Enumerable NFT

An ERC-721 with Enumerable extension, allowing on-chain iteration of all minted tokens.

nft
rustmultibeginner

Soroban Hello World

A minimal smart contract for Stellar's Soroban platform written in Rust.

infrastructure
typescriptethereumadvanced

Batch Read with Multicall

Batch multiple contract reads into a single RPC call using viem's multicall.

integration
pythonbeginner

Keccak256 Hashing (Python)

Compute Keccak-256 hashes in Python, matching Solidity's keccak256 function.

security
vyperethereumbeginner

Vyper ERC-20 Token

A minimal ERC-20 token implementation in Vyper, showcasing Vyper's clean syntax and built-in overflow protection.

tokens
typescriptethereumintermediate

Deploy Contract with viem

Deploy a smart contract using viem with bytecode and ABI.

infrastructure
rustsolanaintermediate

Anchor Program — Solana Counter

A Solana counter program using the Anchor framework with PDA-based state storage.

infrastructure
solidityethereumintermediate

NFT Royalty Enforcement (ERC-2981)

Implement ERC-2981 royalty standard to inform marketplaces of creator royalties.

nft
typescriptsolanaintermediate

Solana Token Transfer (TypeScript)

Transfer SPL tokens between wallets using @solana/web3.js and @solana/spl-token.

integration
typescriptethereumadvanced

Merkle Tree Whitelist

Generate a Merkle tree for whitelist verification and verify proofs on-chain.

security
typescriptethereumexpert

ERC-4337 Account Abstraction

Send a UserOp through an ERC-4337 bundler using viem and permissionless.

infrastructure
pythonadvanced

HD Wallet Derivation (Python)

Derive hierarchical deterministic (HD) wallet addresses from a mnemonic using BIP-32/BIP-44 in Python.

security
solidityethereumintermediate

Chainlink Price Feed (Solidity)

Read token prices from Chainlink price feeds in a Solidity contract.

integration
pythonintermediate

Merkle Proof Verification (Python)

Build a Merkle tree and verify proofs in Python for whitelist verification.

security
solidityethereumadvanced

ERC-4626 Tokenized Vault

A standard ERC-4626 tokenized vault that accepts deposits, issues shares, and accrues yield from an underlying strategy.

defi
solidityethereumintermediate

Simple Staking Contract

A basic staking contract where users stake tokens and earn rewards proportional to their stake.

defi
rustmultibeginner

CosmWasm Counter Contract

A simple incrementing counter smart contract for CosmWasm / Cosmos chains.

infrastructure
typescriptethereumintermediate

Estimate Gas with viem

Estimate gas for contract interactions and check balance before sending.

integration