Zenlink DEX Smart Contract is Open Source

Zenlink has received a Web3 Foundation grant to develop a smart contract implementation. This has been delivered successfully and is now open source. In this article, we will show how it works and explain why we implemented the Zenlink DEX Protocol in different ways and the underlying production logic.

Production Logic

According to the technical architecture of Substrate, there are mainly two ways to achieve features on a Substrate blockchain.

The first way is to build a pallet. This could be imported into the chain runtime using coding. This is the most comprehensive way. The runtime can be modified to suit individual requirements.

The second way is to write smart contracts with an ink! pallet then deploy it to the chain. The benefit of this method is that people compile and deploy the smart contract to the parachain ink! module, rather than modify the source code of the parachain.

Zenlink aims to help parachains in the ecosystem by offering them a simple way to implement dex functionalities. In order to create a variety of different ways for teams to integrate dex functionalities into parachains, we created technical solutions for anyone building a complex decentralized exchange using Substrate technology.

“In the past, we have delivered the pallet implementation. Today, the smart contract implementation has been completed and is now open source. It will greatly enrich our ecosystem and provide more options for parachain builder teams.”

— Leo Guo, Head of Zenlink China

Zenlink DEX Smart Contract Overview

The Zenlink DEX Smart Contract consists of two parts: Exchange and Factory.

The Exchange contract is the core of the ZenLink Dex Protocol. It implements the following interfaces:

  • Initializing token trading pairs.
  • Token swaps.
  • Adding/extracting liquidity.
  • Defining the liquidity constant function used throughout the protocol.

The Factory contract can be used to create exchange contracts for any ERC20 token that does not already have one. It also functions as a registry of ERC20 tokens that have been added to the system, and the exchange with which they are associated.


The whole compilation and deployment procedure is relatively simple and easy.

Firstly, people download the repo to their local machine by using

git clone [git@github.com](mailto:git@github.com):zenlinkpro/zenlink-dex-contract.git

Secondly, we recommend using docker to run a substrate node and compile the contracts.

docker run -p 9944:9944 zenlinkpro/dex:zenlink-canvas-nodecd erc20sudo docker run --rm -v "$PWD":/build -w /build zenlinkpro/dex:zenlink_contract_builder cargo +nightly-2020-10-06-x86_64-unknown-linux-gnu contract buildsudo docker run --rm -v "$PWD":/build -w /build zenlinkpro/dex:zenlink_contract_builder cargo +nightly-2020-10-06-x86_64-unknown-linux-gnu contract generate-metadata

Then we can find the erc20.wasm and metadata.json in the target folder.

Because the factory project depends on the exchange project, the command must be run in the factory project parent folder.

sudo docker run --rm -v "$PWD":/build -w /build/factory zenlinkpro/dex:zenlink_contract_builder cargo +nightly-2020-10-06-x86_64-unknown-linux-gnu contract build

Thirdly, people need to upload and deploy the .wasm files to the blockchain by using canvas-ui.


Finally, people can test the dex functionalities, such as initialize_factory, create_exchange, token swap, etc.

For more setup and test details, please visit Zenlink DEX Smart Contract Repo.

About Zenlink and the Web3 Foundation Grant

The Web3 Foundation Grants Program seeks to allocate resources to projects that are beneficial to the advancement of the Polkadot ecosystem. It has supported many famous ecosystem projects, such as Acala, PolkaWorld, PolkaWallet, etc.

We are honored that the Zenlink DEX Smart Contract implementation is also a recipient of a Web3 Grant. Zenlink is currently building on Substrate, using its technology to share pooled liquidity across digital assets and parachains in the Polkadot network.

Learn more about Web3 Foundation by visiting their website. To learn more about Web3 Foundation’s latest developments, join them on Reddit or Twitter.




Zenlink consists of Zenlink DEX Protocol, Zenlink DEX Module, Zenlink DEX Aggregator and other DEX on Polkadot network.

Recommended from Medium

Weekly Tech Report

Smart Contract Platform Comparison(Programmer explain)

Case Study: Wireframing an educational app for the new internet

What is Paymon App? Paymon App vs. Mixin App (the market cap of 523 million USD)*

17 ways Blockchain can help us meet the United Nations’ Sustainable Development Goals

Lampix CrowdSale Token Launch

Deploy your first smart contract on the INT4.0 testnet

How To Choose The Right Blockchain Technology

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


Zenlink is a cross-chain DEX protocol based on Polkadot.

More from Medium

Linear Finance Telegram AMA Recap (24/05/2022)

Bifrost 2022 May Monthly Report

Chaotic Meme Contest Winners

DeNet partners with Gravity Finance