The main goals of ink! are correctness, conciseness, and efficiency.
ink! is designed to be as close to the Rust programming language as possible. The language uses attribute macros to tag standard Rust structures into understandable contract components.
Because ink! follows Rust standards, tools like
rust-analyzer already work out of
ink! should still feel familiar to developers who have programmed using other modern smart contract languages. The skeleton of a contract has all of the same components that you might expect:
- Event Topics
- Constructor Functions
- Message Functions
ink! supports custom type definitions needed to interact with the Substrate runtime. By default,
ink! has access to all the primitive Substrate types like
You can specify and interact with additional types which may be specific to your Substrate runtime environment.
Being written in Rust, ink! can provide compile-time overflow/underflow safety. Using a Rust compiler configuration, you can specify whether you want to support overflowing math, or if you want contract execution to panic when overflows occur. No need to continually import "Safe Math" libraries, although Rust also provides integrated checked, wrapped, and saturated math functions.
Note: There are some known issues regarding functionality of compiler level overflow checks and the resulting size of the Wasm blob. This feature may change or be iterated on in the future.
ink! provides a built in test environment that can be used to perform off-chain unit testing with the Rust framework. This makes it simple and easy to ensure that your contract code functions as expected, without the need for third party testing platforms.
ink! vs Solidity
Rust is an ideal smart contract language. It is type safe, memory safe, and free of undefined behaviors. It generates small binaries because it doesn’t include extra bloat, like a garbage collector, and advanced optimizations and tree shaking remove dead code. Through compiler flags, Rust can automatically protect against integer overflow.
ink! chooses not to invent a new programming language, but rather adapt a subset of Rust to serve this purpose. As a result, you gain from all of the tooling and support available to the Rust ecosystem for free. In addition, as the language develops, ink! will automatically gain access to new features and functionality, improving how you can write smart contracts in the future.
Here is a brief comparison of features between ink! and Solidity:
|Virtual Machine||Any Wasm VM||EVM|
|Encoding||Wasm||EVM Byte Code|
|Overflow Protection||Enabled by default||None|
|Tooling||Anything that supports Rust||Custom|
|Storage Entries||Variable||256 bits|
|Has Interfaces?||Planned (Rust Traits)||Yes|
- Learn about the SRML Contracts module which is used to deploy and execute ink! contracts.
Visit the reference docs for the ink! abi.
Visit the reference docs for the ink! core.