Solidity vs ink! for writing smart contracts

Solidity vs ink! for writing smart contracts

Covering the differences and advantages for both when writing smart contracts, as well as an in-depth explanation to ink! and how it stands out.

What is a Smart Contract?

Smart contracts are self-executing, automated applications that run on a decentralized network such as blockchain. A smart contract is an agreement between two people in the form of computer code. They run on the blockchain, so they are stored on a public database and cannot be changed. One of the best things about the blockchain is that, because it is a decentralized system that exists between all permitted parties, there’s no need to pay intermediaries (Middlemen) and it saves you time and conflict. Blockchains have their problems, but they are rated, undeniably, faster, cheaper, and more secure than traditional systems, which is why banks and governments are turning to them.

To achieve a better understanding, I’ll provide an example. Let’s imagine that Sarah wants to purchase Kyle’s home. This agreement would be formed on the blockchain using a smart contract. This smart contract contains an agreement between Sarah and Kyle.

In the simplest terms, the agreement will look like this: “WHEN Sarah pays Kyle 150 Ether, THEN Sarah will receive ownership of the house”.

Without the use of a smart contract in this scenario, Sarah and Kyle would have to pay lots of fees to third-party companies. Including the bank, a lawyer and a house broker. You find scenarios like this all across society, and nearly every single transaction could be achieved using a smart contract. These smart contracts are written using programming languages such as Solidity and ink! and in this article, we’ll read about how they compare.

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. the language was later developed by the Ethereum project’s Solidity team, led by Christian Reitwiessner. 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 which 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 together. 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 which is planning on bonding with the Polkadot network uses ink!. This is because it provides the most innovate solution for writing smart contracts using the Rust Programming language.

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 required to make it all come together. Rust is a fantastic language that is very well-tailored to blockchain use-cases specifically. Many of the constraints that 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.

Why WebAssembly for Smart Contracts?

  • Wasm is high performance — it’s built to be as close to native machine code as possible while still being platform independent.
  • It facilitates small binaries to ship over the internet to devices with potentially slow internet connection. This is a great fit for the space-constrained blockchain world.
  • It was developed so that code can be deployed in any browser with the same result. Contrary to the EVM it was not developed towards a very specific use case, this has the benefit of a lot of tooling being available and large companies putting a lot of resources into furthering Wasm development.
  • Efficient JIT execution:64 and 32-bit integer operation support that maps one-to-one with CPU instructions.
  • Wasm expands the family of languages available to smart contract developers to include Rust, C/C++, C#, Typescript, Haxe, and Kotlin. This means you can write smart contracts in whichever language you’re familiar with, though we’re partial to Rust due to its lack of runtime overhead and inherent security properties.

Why Rust for Smart Contracts?

  • 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 the WebAssembly.
  • Tooling: Because ink! follows Rust standards, tools like rustfmt, clippy and rust-analyzer already work out of the box. Same goes for code formatting and syntax highlighting in most modern text editors. 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 for that, since it reorders struct fields in order 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

In summary

Smart Contracts have the potential to provide solutions to many different avenues of many markets in today’s society. The relationship between a business and its customers is built on trust. When trust is broken, contracts are what people fall back on. In certain circumstances, it’s true that one participant doesn’t hold up their end of the agreement. Smart contracts provide a solution to these undependable circumstances and create a more delightful and efficient service experience. This helps get everyone closer to a more decentralized and autonomous society where we do not have to rely on intermediaries. The continuous expansion and innovation of smart contract technology like ink! will proceed to move the needle and provoke more mainstream adoption of blockchain technology as the utility is realized. At the end of the day, you should identify what platform you want to build on top of, and understand the different tools that are at your disposal and what you are most interested in contributing to. That will help you make an informed decision on what programming language is ideal for you.

For more information on Polkadot and Edgeware:

Polkadot’s Website / Edgeware’s Website / Substrate

Join the discussion!

Polkadot’s Twitter / Edgeware’s Twitter / Edgeware’s Telegram / Polkadot’s Telegram / Polkadot’s Github