1. Home
  2. /
  3. Ink
  4. /
  5. Ink! Whitelist Access

Ink! Whitelist Access - Ink Typing CST Test

Loading…

Ink! Whitelist Access — Ink Code

Only whitelisted users can perform a restricted action.

#[ink::contract]
mod whitelist {
	#[ink(storage)]
	pub struct Whitelist {
		owner: AccountId,
		allowed: ink::storage::Mapping<AccountId, bool>,
	}

	impl Whitelist {
		#[ink(constructor)]
		pub fn new() -> Self {
		Self { owner: Self::env().caller(), allowed: ink::storage::Mapping::new() }
		}

		#[ink(message)]
		pub fn add(&mut self, user: AccountId) {
		assert!(self.env().caller() == self.owner);
		self.allowed.insert(user, &true);
		}

		#[ink(message)]
		pub fn restricted(&self) {
		assert!(self.allowed.get(self.env().caller()).unwrap_or(false));
		}
	}
}

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.

More Ink Typing Exercises

Ink! Simple Counter ContractInk! Owner-Only MessageInk! Simple ERC20 TokenInk! Simple Vault (Deposit + Withdraw)Ink! Timelock ContractInk! Simple VotingInk! Event LoggerInk! Immutable Config ExampleInk! Simple Multiplier

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher