Viewing Version 5

v5.x

Getting Started

Basics

Testing & Debugging

Macros & Attributes

Storage & Data Structures

Linter

Frontend Development

ink! Examples

Standards

Funding Programs

Third Party Tools & Libraries

FAQ

Attention

You are browsing old docs. Click here to switch to the latest version.

Attention

You are browsing old docs. Click here to switch to the latest version.

How it Works — Substrate

Version: 5.x

How it works – Substrate

ink! is a programming language for smart contracts; blockchains built with the Substrate framework can choose from a number of smart contract languages which one(s) they want to support. ink! is one of them. It is an opinionated language that we have built by extending the popular Rust programming language with functionality needed to make it smart contract compatible.

How does ink! tie into Substrate?

Substrate is a framework for building blockchains – those can be standalone blockchains or blockchains connected to Kusama or Polkadot, so called parachains. Substrate contains a number of modules, in Substrate terminology those are called pallets. Substrate comes with a set of pallets for many requirements modern blockchains typically have – staking, fungible tokens, non-fungible tokens, governance, etc.

Substrate also ships with a module for smart contracts, this module is called pallet-contracts. If a parachain is developed in Substrate it can easily add smart contract functionality by including this pallet.

How does ink! come into play here? ink! is a programming language, specifically it is an embedded domain-specific language for the popular Rust programming language. This means that you can use all the normal Rust syntax plus some specifics that we added to make the language suitable for the smart contract world. The pallet-contracts takes these ink! contracts and executes them safely. So in short: with ink! you can write smart contracts in Rust for blockchains built with Substrate that include pallet-contracts.

How it works – Substrate

ink! is a programming language for smart contracts; blockchains built with the Substrate framework can choose from a number of smart contract languages which one(s) they want to support. ink! is one of them. It is an opinionated language that we have built by extending the popular Rust programming language with functionality needed to make it smart contract compatible.

How does ink! tie into Substrate?

Substrate is a framework for building blockchains – those can be standalone blockchains or blockchains connected to Kusama or Polkadot, so called parachains. Substrate contains a number of modules, in Substrate terminology those are called pallets. Substrate comes with a set of pallets for many requirements modern blockchains typically have – staking, fungible tokens, non-fungible tokens, governance, etc.

Substrate also ships with a module for smart contracts, this module is called pallet-contracts. If a parachain is developed in Substrate it can easily add smart contract functionality by including this pallet.

How does ink! come into play here? ink! is a programming language, specifically it is an embedded domain-specific language for the popular Rust programming language. This means that you can use all the normal Rust syntax plus some specifics that we added to make the language suitable for the smart contract world. The pallet-contracts takes these ink! contracts and executes them safely. So in short: with ink! you can write smart contracts in Rust for blockchains built with Substrate that include pallet-contracts.

How does the pallet-contracts work?

We intentionally designed pallet-contracts in a way that it is decoupled from the language that is used to write smart contracts. The pallet is only the execution environment and it takes WebAssembly files as input. Smart contracts for this pallet have to be compiled to the WebAssembly (Wasm) target architecture.

For contract developers this means they can use ink! for writing smart contracts, but can also decide on other languages. Right now three languages to choose from exist:

It's not hard to add new languages. There just needs to be a compiler for the language down to WebAssembly, then it's possible to implement the API of pallet-contracts. This API at the moment consists of about 50 functions for anything a smart contract may desire: storage access, cryptographic functionality, environmental information like block numbers, access to functions for getting random numbers or self-terminate the contract, etc. Not all of those have to be implemented in the language ‒ the ink! "Hello, World!" requires just six API functions. The following schema depicts this relationship:

We think this design is more future-proof than some architectures found in competing ecosystems. There is no tight coupling between language and execution environment. WebAssembly is an industry standard and a multitude of programming languages can nowadays be compiled down to WebAssembly. If in, say ten years time, researchers come up with an innovative language for writing smart contracts (or a subset of an existing language) then as long as there is a WebAssembly compiler it will be easy to make this language compatible with pallet-contracts.

Quotes

Quoted text

Quoted quote

Quoted quote text

Toggles

Toggle me!

Toggle me!

Admonitions
DANGER

Some content with Markdown syntax. Check this api.

DANGER

Some content with Markdown syntax. Check this api.

WARNING

Some content with Markdown syntax. Check this api.

WARNING

Some content with Markdown syntax. Check this api.

TIP

Some content with Markdown syntax. Check this api.

TIP

Some content with Markdown syntax. Check this api.

INFO

Some content with Markdown syntax. Check this api.

INFO

Some content with Markdown syntax. Check this api.

NOTE

Some content with Markdown syntax. Check this api.

NOTE

Some content with Markdown syntax. Check this api.

We think this design is more future-proof than some architectures found in competing ecosystems. There is no tight coupling between language and execution environment. WebAssembly is an industry standard and a multitude of programming languages can nowadays be compiled down to WebAssembly. If in, say ten years time, researchers come up with an innovative language for writing smart contracts (or a subset of an existing language) then as long as there is a WebAssembly compiler it will be easy to make this language compatible with pallet-contracts.

Use Case 1: Smart Contracts as "first-class citizens"

Use Case 2: Smart Contracts as "second-class citizens"

Use Case 3: Smart Contracts as a first step into Polkadot or Kusama

Get In Touch

© use.ink 2025. All rights reserved.

Get In Touch