Code Snippets

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

18 snippets

javascriptethereumbeginner

Sign Message with ethers.js

Sign and recover messages for authentication using ethers.js.

security
solidityethereumintermediate

Chainlink Price Feed (Solidity)

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

integration
solidityethereumintermediate

ERC-721 Enumerable NFT

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

nft
pythonintermediate

Merkle Proof Verification (Python)

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

security
pythonbeginner

Keccak256 Hashing (Python)

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

security
pythonethereumbeginner

Gas Price Monitoring (Python)

Monitor current gas prices and EIP-1559 fee suggestions using web3.py.

integration
pythonintermediate

ABI Encode/Decode (Python)

Encode and decode ABI-calldata in Python for contract interaction.

integration
pythonethereumintermediate

Web3.py Event Listening

Listen to and decode smart contract events using web3.py.

integration
solidityethereumintermediate

Token Vesting Contract

A linear token vesting contract that releases tokens over time with a cliff.

defi
solidityethereumadvanced

Simple AMM Swap (Solidity)

A minimal constant-product AMM (x*y=k) swap function, like Uniswap V2.

defi
typescriptethereumadvanced

EIP-712 Typed Data Signing

Sign and verify EIP-712 typed structured data for secure off-chain signatures.

security
pythonadvanced

HD Wallet Derivation (Python)

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

security
solidityethereumintermediate

NFT Royalty Enforcement (ERC-2981)

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

nft
typescriptethereumexpert

ERC-4337 Account Abstraction

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

infrastructure
typescriptethereumadvanced

Merkle Tree Whitelist

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

security
javascriptintermediate

IPFS Upload with Pinata

Upload metadata or images to IPFS via Pinata's API for NFT metadata.

infrastructure
typescriptethereumintermediate

Estimate Gas with viem

Estimate gas for contract interactions and check balance before sending.

integration
rustsolanaintermediate

Anchor Program — Solana Counter

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

infrastructure