Learn Ink - 10 Code Examples & CST Typing Practice Test
Ink! is a Rust-based eDSL (embedded domain-specific language) for writing smart contracts on the Substrate blockchain framework. It emphasizes safety, efficiency, and tight integration with Polkadot and Substrate ecosystems.
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
Frequently Asked Questions about Ink
What is Ink?
Ink! is a Rust-based eDSL (embedded domain-specific language) for writing smart contracts on the Substrate blockchain framework. It emphasizes safety, efficiency, and tight integration with Polkadot and Substrate ecosystems.
What are the primary use cases for Ink?
High-security smart contracts. DeFi protocols on Substrate. NFT minting and marketplaces. On-chain governance modules. Wasm-based blockchain apps
What are the strengths of Ink?
Safe, type-checked contracts. High performance via Wasm. Strong ecosystem support in Polkadot. Auditable Rust code. Predictable gas and storage behavior
What are the limitations of Ink?
Limited to Substrate/Wasm chains. Smaller ecosystem than Solidity/EVM. Requires Rust proficiency. No EVM compatibility. Less tooling for testing vs EVM chains
How can I practice Ink typing speed?
CodeSpeedTest offers 10+ real Ink code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.