Substrate & ink!
Build blockchains with Substrate FRAME pallets and smart contracts with ink! - Rust-native Web3 infrastructure.
Busca en todas las páginas de la documentación
Build blockchains with Substrate FRAME pallets and smart contracts with ink! - Rust-native Web3 infrastructure.
Minimal ink! contract skeleton:
#[ink::contract]
mod flipper {
#[ink(storage)]
pub struct Flipper {
value: bool,
}
impl Flipper {
#[ink(constructor)]
pub fn new(init: bool) -> Self {
Self { value: init }
}
#[ink(message)]
pub fn flip(&mut self) {
self.value = !self.value;
}
#[ink(message)]
pub fn get(&self) -> bool {
self.value
}
}
}When to reach for this:
Pallet storage and dispatch pattern (conceptual FRAME snippet):
#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::storage]
pub type Value<T> = StorageValue<_, u32, ValueQuery>;
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000)]
pub fn set(origin: OriginFor<T>, v: u32) -> DispatchResult {
ensure_signed(origin)?;
<Value<T>>::put(v);
Ok(())
}
}
}What this demonstrates:
ensure_signed authorization guardset_code governance.pallet-contracts with rent and storage trie.| Layer | Responsibility |
|---|---|
| FRAME pallet | Chain logic, tokens, governance |
| ink! contract | User-deployed app logic on chain |
Result from messages, avoid unwrap.frame_benchmarking.| Alternative | Use When | Don't Use When |
|---|---|---|
| Solana programs | Deploy on existing high-TPS chain | Need custom consensus |
| Cosmos SDK (Go) | Team Go-heavy | Want Rust end-to-end |
| Hardhat Solidity | EVM liquidity | Custom Substrate runtime features |
| Rollup framework | Ethereum security | Standalone L1 requirements |
Chain-level rules in pallets; user apps in ink! if contracts pallet enabled on runtime.
substrate-node-template or pop up for local chain with instant blocks for tests.
Governance proposal calls set_code with new Wasm runtime - plan migration storage hooks.
ink! is Rust/Wasm; tooling smaller than EVM but fits Polkadot ecosystem.
#[ink::test] unit tests run on host; integration needs substrate-contracts-node.
Polkadot parachains use XCM for asset messaging - separate learning path from basic pallet.
Transaction payment pallet charges based on weight and length; benchmark honestly.
#[ink(storage)] fields cost rent; design minimal state per contract instance.
Aura/BABE/GRANDPA etc. depend on node template - solochain vs parachain differs.
Audit pallet dispatchables and ink! messages - see Security & Auditing.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026