Ink! Owner-Only Message - Ink Typing CST Test
Loading…
Ink! Owner-Only Message — Ink Code
A contract where only the owner can update a stored message.
#[ink::contract]
mod owner_message {
#[ink(storage)]
pub struct OwnerMessage {
owner: AccountId,
message: ink::prelude::string::String,
}
impl OwnerMessage {
#[ink(constructor)]
pub fn new() -> Self {
Self {
owner: Self::env().caller(),
message: String::from(""),
}
}
#[ink(message)]
pub fn set_message(&mut self, msg: String) {
assert!(self.env().caller() == self.owner);
self.message = msg;
}
}
}Ink Language Guide
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.
Primary Use Cases
- ▸High-security smart contracts
- ▸DeFi protocols on Substrate
- ▸NFT minting and marketplaces
- ▸On-chain governance modules
- ▸Wasm-based blockchain apps
Notable Features
- ▸Rust-based syntax
- ▸Compile-time type safety
- ▸Wasm target for Substrate
- ▸Macros for contract boilerplate
- ▸Support for storage, events, and messages
Origin & Creator
Ink! was created by Parity Technologies, the team behind Substrate and Polkadot, to provide a safe Rust-based smart contract language for WebAssembly chains. Initial development started around 2018.
Industrial Note
Ink! is primarily used in Substrate-based chains and Polkadot parachains, for high-assurance contracts in DeFi, on-chain governance, NFT minting, and other blockchain-native applications.