Zilliqa + Scilla | Exploring Sharding

Nico Zahniser
Exploring the Blockchain
3 min readAug 31, 2019

Sharding is a concept that’s widely used in databases, to make them more efficient. A shard is a horizontal portion of a database, with each shard stored in a separate server instance.

In essence of using a blockchain, nodes that maintain a shard maintain information only on that shard in a shared manner, so within a shard, the decentralization is still maintained.

Let’s get started into Zilliqa, which is the first sharding blockchain on mainnet. It uses Scilla, short for Smart Contract Intermediate-Level Language, is an intermediate-level smart contract language being developed for Zilliqa.

HelloWorld is usually good place to start for practice, we also have to find a good editor, or IDE that can help verify contracts before trying to deploy.

HelloWorld.scilla

Let’s start with a look at the classical “HelloWorld” contract.

Libraries

A Scilla contract may come with some helper libraries that declare purely functional components of a contract.

A library is declared in the preamble of a contract using the keyword library followed by the name of the library.
HelloWorld contract code has a function one_msg in the library and two global constants.

Standard libraries shipped with the language can be added using the keyword import followed by the name of the library.

Code Snippet: “HelloWorld”

(Im)mutable variables

Scilla contracts use two types of state variables: mutable and immutable.

Immutable variables are those that get initialized at the time of contract creation. Once initialized, their values cannot be changed. HelloWorld has one immutable variable named owner.

Mutable variables are those whose value will change even after the contract has been created. HelloWorld has one mutable variable named welcome_msg.

Functions // Transitions

Transitions are functions that change the value of mutable variables and can communicate with other contracts.

The first transition, setHello, takes a String as input, updates welcome_msg and informs the caller of the success/failure.

The second transition, getHello, simply sends out a message to the caller with the current value of welcome_msg.

Finding an IDE

Scilla developed an easy way to test basic contracts out in a browser environment. Scilla IDE

From there you can go to the far right tab and deploy the contract and see if you have success.

While yes, I think we all got PTSD from “Along Came Polly” , and the infamous discovery of the word ‘sharting’. Sharding does have great potential

Final Thoughts

Hopefully you gained some more information about a sharding blockchain and just a little bit of understanding of how the code works.

Wider adoption of sharding requires the blockchain and crypto developers to work on an important area.

While communication between nodes within a shard is smooth, inter-shard communication is currently not easy and requires the development of a separate protocol.

Addressing this key requirement will potentially result into a wider adoption of sharding, and that’ll help blockchains handle higher transaction throughput .

--

--