PixelPlex

How We Migrated 0x to Echo. Technical Details

Blog17 January, 2020

Technical Details on how we've migrated 0x DEX Project to Echo. Migration of the frontend, backend and monorepo.

While working on Echo’s architecture, we’ve considered a huge number of technologies, mechanisms, and other projects. That’s because we wanted to pick value-based and intuitive techniques and approaches that would be familiar to anyone. We were also looking to ultimately reduce the hurdles for those who wish to enter the Echo world, so we did our best to ensure a low learning curve.

 

Below are some of the mechanisms we chose to implement:

  • Account nicknames instead of complex addresses;
  • Smart contract fee pool mechanism that allows to use smart contract calls at the expense of the pool balance;
  • Fast transaction confirmation times with an extremely low fork probability;
  • Participation in the block creation process granted to each account throughout the network. No need to waste tons of money on mining equipment and balance stacking

 

Sure enough, blockchain can’t exist without apps built upon its network. That’s why we decided to make Echo and its interface as simple and clear as possible for developers. This was the key factor that urged us to build our own x64 virtual machine. 

The solution will enable developers to create dApps on Echo by using the languages they are already familiar with. To date, Echo supports C++, and we are about to add Rust and Go, thus expanding both the virtual machine and Echo capabilities as a whole.

However, considering the fact that most blockchain- and smart contract-based apps are built on Solidity, we’ve made our mind to first adapt and optimize Echo interface for the community that’s already familiar with Ethereum. Accordingly, we focused our efforts on providing an Ethereum-compatible environment that would require minimal changes to migrate apps from Ethereum to Echo. This approach will remove the technical barriers for the developers who are familiar with Ethereum and Solidity, while letting them use their go-to toolkits to develop amazing new applications.

Migration of 0x DEX Project to Echo Network

It’s not so easy to judge the convenience of app interface, approach, or technology without having tried it first. That is why we delved into the migration process, digging ourselves into a totally unfamiliar code. Here we’d like to take a moment to thank the 0x development team for their clear high-quality source code.

Here is what we had at the start:

  • Three original 0x’s repositories that included a frontend code, a blockchain, and a monorepo with all kinds of libraries in it;
  • Echo Bridge app: Chrome extension similar to Metamask used in the original 0x;
  • Echojs-lib library to communicate with the Echo node;
  • A native WS interface of the Echo node;
  • A bunch of skilled developers and twice as many hands to craft with.

Frontend’s Migration

Here are the issues we faced during the migration process:

  1. A totally different blockchain interface;
  2. An account-based blockchain model that requires initial account registration.

 

To tackle both of the issues, we took the Echo Bridge and developed an additional interface in it. The interface implements similar methods that Metamask extension offers while hiding the entire logic of the background query processing. You can learn more about how to use the Echo Bridge extension here:

 

Overriding an ethereum object on an Echo Bridge-connected page isn’t quite a typical behavior,  that’s why we’ve built a special add-on to start this process. The add-on is packaged within the echo-web3 library. This way, the process of connecting an Ethereum-based app to the Echo network went down to just adding the echo-web3 library to the dependencies and then initializing methods overriding via polyfill initialization:

typescript

import { EchoPolyfill } from ‘echo-web3’;

    await EchoPolyfill();

Voilà: the mission of frontend migration to Echo was completed by using just a few code lines! The app started working with Echo network-connected accounts and now treats them as Ethereum addresses, builds and signs transactions through Bridge while perceiving it as Metamask

Backend’s Migration

The app’s backend communicates with the blockchain directly through the RPC requests. Rebuilding a large portion of existing echojs-lib interactions was unreasonable and way too complex to fit our objective. Instead, we’ve built an extra utility server that provided a similar to Ethereum’s interface and converted requests into a format that sat well with Echo.

We should note that the utility was created with NodeJS, which only proves the possibility of such an integration. Later, we added to the blockchain roadmap the task to develop an Ethereum API compatible interface for the native node.

This utility’s implementation can be found here.

The key advantage of this approach was that there was no need to make any changes to the app’s backend code, some config updates were enough.

Monorepo’s Migration

The job was almost done. Both the frontend and the backend were linked to the Echo network and worked well with blockchain accounts. The last task was to safely deploy the system’s smart contracts to the Ethereum network. By using the same RPC adapter, we configured the connection to Echo. The smart contract deployment process requires transaction signing, so we finalized the echo-web3 library and integrated it into the smart contract management mechanism.

Everything was ready for smart contracts’ deployment to the network. However, having studied the smart contract’s code, we realized that we couldn’t do it under a 10-line code limit. The major concern was that the smart contracts use ecrecover method that enables to verify and restore the original address. The address private key is used to sign the data. The whole mechanism is based on the ECDSA signature schemes family that’s used on the Ethereum network. Yet, Echo protocol utilizes the EdDSA signature scheme that does not support public key recovery. That’s why the ecrecover mechanism cannot be properly used.

EIP-0001 became the solution to that issue. You can learn more about it here.

Eventually, we’ve implemented the approach together with establishing a connection to the 0x’s smart contracts. The smart contracts were successfully deployed in the Echo network. We installed these smart contracts’ addresses to our system’s config files, which enabled us to consistently launch the 0x application.

A slightly modified app version (we have updated some headers and pictures) can be found here.

Before you launch the app, make sure you have the Echo Bridge extension installed.

A Conclusion Note

As you can see, migrating Ethereum dApps to Echo is now a quick and easy task. It opens up new exciting opportunities and definitely facilitates global blockchain adoption.

In case you have any questions or suggestions, we’ll be happy to handle them in our Echo Discord channel.

Contact us
Get in touch with us and let's get your project started today!