Token distributors in Scilla

This article explains how the Merkle tree-based token distributors work on Zilliqa using Scilla. The implementations of this contract can be found in Zwap weekly distribution, REDC LMR distributions, and others as well.

Most of the platforms use merkle tree-based distributors because transferring tokens to individual accounts would cost too much gas. Also, updating the contract addresses and their amount in the distributor contract itself. This is where merkle tree-based distributors come in. They enable platforms to distribute tokens through distributors in a more simplified and gas-efficient way. Merkle roots are used to verify whether the address claiming token from the contracts is valid or not.

Source: https://en.wikipedia.org/wiki/Merkle_tree

From all the addresses and the amount to which the tokens are to be distributed, merkle root is calculated. An admin/oracle/backend updates the distributor contract with the merkle root.

Zwap distributor contract’s transition for setting merkle root

After the merkle root is set, the address which is supposed to get the tokens from the distributor, generates a merkle hash proof from the backend of the distributors and supply the epoch number(the period of token distribution), amount, and proof of the leaf node. The distributor contract verifies the proof and distributes the token to the users who are claiming tokens.

Zwap distributor contract’s transition for claiming token

The data provided by the users to claim tokens with the merkle proof consists of epoch number, address, amount, and an array of proof hashes as below.

Data inputs for claim transition of the distributor contract

Code References

Zwap distributor contract

Zwap distributor backend

Script for setting merkle root and claiming tokens

More detailed description about merkle trees and the code can be found in the next article of Merkle tree and proofs for distributor.

--

--

--

Publication where developers building on top of zilliqa blockchain share their learnings.

Recommended from Medium

Add Chat Feature to Demo of Amazon Chime SDK React Component Library

Scrabbling with Javascript

Drawing on the HTML5 Canvas with a Mouse

God’s city Records lines up C-jaze, Josh liberty and Dj Jackson on new single ‘GOD’S PLAN’.

My Three Current Conference Talk Proposals

The HTML,CSS & JAVASCRIPT affair - A layman analogy!

MEMES — Who has somebody like this?…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bibek Koirala

Bibek Koirala

A blockchain dev | Zilliqa Developer Ambassador | RedChillies Labs, Inc. | Pastel Soft | JS Security Technologies | AART

More from Medium

1Inch Exchange Clone Script: Forge A 1Inch Exchange-Like Dex Aggregator

THOTful Thursday with Regan

Connect MetaMask to Polygon Network — Aurus Token Contract Addresses

The $BLES Double Chance Lottery: Now Live on Polygon