Learn INK with Real Code Examples
Updated Nov 25, 2025
Explain
Ink! uses Rust syntax with domain-specific macros for blockchain smart contracts.
It provides compile-time safety and strong typing, reducing runtime errors.
Contracts compile to WebAssembly (Wasm) to run on Substrate-based chains.
Designed for formal verification and predictable execution.
Used in DeFi, NFTs, and governance applications within Polkadot and Kusama ecosystems.
Core Features
#[ink(storage)] for state
#[ink(event)] for events
#[ink(message)] for callable functions
Cross-contract calls
Metadata generation for contracts
Basic Concepts Overview
Storage struct holds contract state
Messages are public callable functions
Events record contract activity
Cross-contract calls allowed via ink! traits
Constructor initializes contract state
Project Structure
lib.rs - main contract code
Cargo.toml - Rust project config
tests/ - Rust unit tests
target/ - compiled Wasm artifacts
metadata.json - ABI for frontend interaction
Building Workflow
Write Rust + Ink! macros
Compile to Wasm
Generate metadata
Deploy to Substrate testnet
Interact via Polkadot.js or API
Difficulty Use Cases
Beginner: simple storage contract
Intermediate: token contracts
Advanced: NFT marketplace
Expert: multi-contract governance logic
Auditor: Wasm & Rust contract analysis
Comparisons
Ink! vs Solidity: Ink! is Rust-based and Wasm-native; Solidity is EVM-native.
Ink! vs Vyper: Ink! runs on Substrate/Wasm; Vyper runs on EVM.
Ink! vs Solidity + EVM: Ink! has strong Rust type safety; Solidity has larger ecosystem.
Ink! vs Move: Move is resource-based, Ink! is Rust/Wasm based.
Ink! vs Cairo: Cairo targets STARKs; Ink! targets Substrate/Wasm chains.
Versioning Timeline
2018 – Initial Ink! prototypes
2019 – ink! 1.0
2020 – ink! 2.0 with macros
2021 – PSP standards introduced
2022–2025 – Continuous tooling and compiler improvements
Glossary
Wasm: WebAssembly
Storage: contract state
Message: callable function
Event: emitted log
Constructor: initializer function