ink!

Honestly, I am new to blockchain. From my point of view, Solidity language is shit, and I don't know why Gravin Wood designed Solidity like that. Even if you are an experienced programmer, you need a lot of time to get familiar with Solidity. But it's easy to write contracts with ink! if you are a rust programmer.

pragma solidity ^0.4.22;

contract helloworld {
    function helloworld() public pure returns (string) {
        return 'helloWorld';
    }
}

I don't know why we put the public keyword at the back other than every other language does.

What is ink!§

ink! is a programming language invented by Parity for building blockchain contracts like Solidity does.

How's ink! work?§

As we know, contracts are on-chain logic, they cannot run on a standard OS, so we need a virtual machine to interpret the compiled code. So does ink!. The contracts written by ink! will be compiled into WASM. In substrate runtime, the pallet called contracts will run the WASM code.

ink! vs Solidity§

Solidity§

Solidity is the code behind Ethereum — one of the largest blockchain platforms in the world. Computer scientist Dr. Gavin Wood originally came up with the concept of the Solidity language in August 2014.

Solidity is an object-oriented, high-level language for implementing smart contracts. Solidity was influenced by C++, Python, and JavaScript and is designed to target the Ethereum Virtual Machine (EVM). It is a statically typed scripting language that does the process of verifying and enforcing the constraints at compile-time as opposed to run-time.

Pros of Solidity

  • Solidity provides inheritance properties in contracts including multiple-level inheritance properties.
  • Can arguably be easier to learn in comparison to an eDSL (embedded domain-specific language) like ink! because of Solidity's similarity to other more commonly used high-level languages.
  • Multiple type-safe functions are also supported in Solidity through facilitating ABI(Application Binary Interface).
  • Widely used as the smart contract programming language of choice when working within the Ethereum blockchain as it's custom made to work with the Ethereum blockchain. This means much more support from a much larger community that has had time to work through bugs and provide a more user-friendly/dev-friendly environment.

ink!§

ink! is a Rust-based embedded domain-specific language (eDSL) for writing WebAssembly smart contracts specifically for the FRAME Contracts pallet created by Parity Technologies. Also founded by Dr. Gavin Wood, Parity has developed Substrate, a framework for building blockchains, and Polkadot, the next-generation platform for connecting independent blockchains.

The Polkadot Relay Chain will not support smart contracts natively. However, parachains on Polkadot will support smart contracts. The smart contracts platform Edgeware, a self-governing blockchain built on top of substrate is planning on bonding with the Polkadot network using ink!.

ink! provides the most flexibility for new and veteran developers because it chooses not to invent a new programming language, but rather adapt a subset of Rust by simply adding some attribute tags in the form of #[ink(…)] to do the magic.

Rust is a fantastic language that is very well-tailored to blockchain use-cases specifically. Many of the constraints you get on the blockchain are identical to those found in high-reliability embedded systems — small code size, excellent security, high reliability, and minimal resource use.

Pros of Rust

  • Rust ecosystem: You gain from all of support available to the Rust ecosystem for free. As the language develops, ink! will automatically gain access to new features and functionality, improving how you can write smart contracts in the future.
  • 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.
  • No overhead: minimal runtime.
  • 1st class Wasm: Rust provides the first class support for WebAssembly.
  • Tooling: Because ink! follows Rust standards, tools like rustfmt, clippy and rust-analyzer already work out of the box. Also, Rust has an integrated test and benchmark runner.
  • Small Size: In the space-constrained blockchain world, size is important. The Rust compiler is a great help since it reorders struct fields to make each type as small as possible. Thus Rust data structures are very compact, in many cases even more compact than in C.

Snapshot Comparison