Mirror - A tool for Enterprise Ethereum dev environment

Sep 18, 2020

Greetings from Consenso Labs. We hope that everyone is keeping safe and sound during these tough times.

We at Consenso Labs have been working passionately to build an arbitration platform to bring efficiency in the digitization of the dispute resolution solutions. We have been building the platform on Enterprise based Ethereum network using Hyperledger Besu. The privacy feature of the platform is something that well suited our solution architecture. It also provided all sorts of flexibility that we were looking for to build an enterprise-level arbitration platform.

Even though we have been building on enterprise based private blockchain for a while now, like most of the other organizations, we too have gained a fair bit of exposure to working on the public chain based infrastructure. We can all agree that a great many tools developed by the Ethereum ecosystem for the mainnet infrastructure make the development very much smoother, especially the onboarding part. Unfortunately, it’s not the same in enterprise solutions.

While tinkering with the platform’s privacy features, we found that there was no easy way for developers to quickly deploy and test the privacy features of the platform. Having built many DApps on the public blockchain we were used to testing and deploying with CLI tools such as Truffle. That’s when we created a simple yet elegant tool to help our developers quickly deploy and test the privacy features. We created this initially just for internal use, but we realized that this could be a handy tool for anyone who is building on the privacy features of Enterprise Ethereum nodes such as Hyperledger Besu. We introduce to you the Mirror tool.

Although this article assumes that you are currently building on Besu platform, we believe that the tool can help even the beginners to conveniently bootstrap their projects. If you are new to Besu client, we urge you to go through the basics of Besu client and features before continuing with this article.

In this blog post, we will take you through all the features of the Mirror tool. But, before getting to know the functionalities of the tool, we would like to elaborate a little more on how exactly this tool could help you if you are building on Enterprise Ethereum, especially Hyperledger Besu.

What is Mirror?

MIrror is a command-line tool that helps developers to compile, deploy, and test the Solidity smart contracts on Enterprise Ethereum nodes (currently on Hyperleder Besu). This tool will help easily test and deploy the contracts on the Besu nodes by exploring all the enterprise features provided by the platform even before any integration. So, no more manually compilation and moving those artifacts between the projects. And no more using those ad-hoc scripts to create those privacy transactions.

Why do you need Mirror?

Isn’t Hyperledger Besu another Ethereum client and can we not use existing tools to build and test on this platform? Yes, and yes. We can definitely use existing tools to build and deploy on Besu clients as they are compatible with public blockchains too. But when it comes to using all the enterprise based privacy features of the Besu client when used along with its private transaction manager node, Orion, we need a modified version of the tool. So, the Mirror tool tries to explore the enterprise feature updates to the Besu clients.

Currently, Mirror tool supports Solidity contracts compilation on any of the compiler version and deploy using privacy transactions. It also supports deployments based on the privacy groups along with onchain privacy features of Besu platform. We feel that deploying the contracts on a privacy group during the development stage helps to easily incorporate the business logic.

We urge you to go through the documentation If you are not familiar with the privacy groups of the Besu platform.

How to get started?

If you have made it so far, we believe that you are already looking for some sort of solution to bootstrap the smart contract development on the Hyperledger Besu client. We have got you covered. Let’s not wait any longer, let’s get started with the fun part.

Mirror CLI tool:

Mirror is a CLI tool similar to the truffle. We have included all the frequently used commands (init, compile, deploy, test) of the truffle tool in our initial release.

Mirror is an NPM tool. Once you have Node.js and NPM installed on your device, all you have to do is install this Node package globally.

$ npm install -g mirror-besu
Installing Mirror tool

Create a sample contract project:

Mirror provides an initialization option to scaffold a basic privacy contract project.

$ mirror init

The init command executed on an empty directory will create a basic project structure as below:

├── contract
│   ├── SomeContract.sol
├── migration
│   ├── index.js
├── wallet
│   ├── keys.js
├── test
│   ├── SomeContract.test.js
├── mirror-config.js
Contract project structure

The contract structure is pretty much similar to the one initialized with truffle. You can store the contracts and tests in `contract` and `test` directories respectively. Apart from this, there are three configurations files. The first one is keys.js where the test keys are stored, mirror-config.js is used to maintain the configuration details of the network and compilers. The last one is miration/index.js where the details related to the privacy deployment are added. Check out the sample files and documentation for more details.

Compiling and deploying the contract:

The mirror tool also generates ABIs and compiled bytecode that is used to deploy the solidity contracts. A deploy operation also compiles all the contracts before deploying them to the nodes. The deploy operation is where the Mirror tool is nifty as it provides privacy-based deployment options.

One can define the group members and rules in the `migration/index.js` file for each of the contract deployment. The mirror will pick these rules and create privacy groups during the deployment. The network configuration maintained in the `mirror-config.js` will expect you to include host RPC endpoint with port and chain ID details. You can also maintain several networks in the `mirror-config.js` file and point the mirror to a network during the deployment.

mirror deploy --network develop
Deploy the contracts to a network named develop

If the besu network is configured with onchain privacy feature you can add an `onchain-privacy` flag to inform the tool about it so that it creates a privacy group onchain. There are several benefits of using onchain privacy. Refer besu docs to learn more about it.

mirror deploy --network develop --onchain-privacy

Mirror supports all kinds of RPC endpoints hosted on any platform. It is also compatible with the network deployed on the BaaS platforms such as Kaleido. Make sure to grab the privacy node address, chain ID, and the authorized RPC endpoint from the Kaleido console and update the `mirror-config.js` accordingly.

Testing the deployed contracts

We all know that writing tests for the contracts are a crucial part, both in terms of logic and security evaluation. So, we have added functionality to write tests even with privacy group features. There is nothing fancy happening here. The tests are written using the Mocha test framework and there is complete liberty to write your tests with other test frameworks.

Mirror picks all the tests from the `test` directory and deploys it with the help of rules specified in the `migration/index.js`.

mirror test --network develop

Where to go from here?

Looks like we have covered all the basic functionalities to get you started with the tool. We know that it’s still not a complete package and we have a lot of things planned to evolve this tool. As you are aware the tool only supports You can check out the detailed documentation and planned roadmap here.

We feel that although a lot of effort goes into standardizing the enterprise based blockchain protocols through alliances, there is still a barrier for onboarding developers who have already partaken in the development public blockchain network. Mirror tool is a small effort to smoothen the onboarding for DApp developers. We look forward to contributing more tools to the enterprise ethereum community. We look forward to any suggestions and contributions to the project.

Demo and resources:

Great! We made it through the post and we hope that it was enough info to get started. We also know that it can be overwhelming sometimes to get onboarded to a new tool with just a blog post, so we have created a demo video to onboard you quickly. Do check it out.

Here are a few more resources to further explore and contribute to mirror. Also, do check out the Arbitration platform that we are building.

We hope that you enjoyed the article and the tool will make experience with Enterprise Ethereum much smoother. We look forward to publishing more articles on Mirror tool with more updates. Have a great day

Koshik Raj

Jazzing @ Consenso Labs

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.