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

While working on Echo’s architecture, we have considered a large number of technologies, mechanisms, and other projects. It was done to pick value-based and intuitive techniques and approaches that would be familiar to everyone.

Also, we were looking to reduce the hurdles for those who wish to enter the Echo world, and so we did our best to ensure the best learning curve.

Below are some of the mechanisms we chose to implement:

  • Account nicknames in place 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 time with extremely low fork probability;
  • Participation in the block creation process granted to each account throughout the network. No need to waste a lot of money on mining equipment and balance stacking.

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

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

Considering that most blockchain and smart contract-based apps are built on Solidity, we have decided to first adapt and optimize Echo interface for the community that is 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 is not so easy to judge the convenience of the app interface, approach, or technology without having tried it first. That is why we delved into the migration process, digging into a totally unfamiliar code. We would like to take a moment to recognize and thank the 0x development team for the clear high-quality source code.

Here is what we started with:

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

Frontend Migration

We faced the following issues during the migration process:

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

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

Overriding an Ethereum object on an Echo Bridge-connected page is not quite a typical behavior. That is why we have 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 the method overriding through polyfill initialization:

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, and builds and signs transactions through Bridge while perceiving it as Metamask.

Backend Migration

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

The utility was created with NodeJS, which 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. The 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, only some configuration updates were enough.

Monorepo’s Migration

The job was almost done. Both the frontend and the backend were linked to the Echo network and it worked well with the 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 the 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 the smart contracts’ deployment to the network. However, having studied the smart contract’s code, we realized that we could not 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 scheme family that is used on the Ethereum network.

Echo protocol utilizes the EdDSA signature scheme that does not support public key recovery. That is why the ecrecover mechanism could not be properly used.

Echo Protocol EIP-0001 was the solution for this issue. You can learn more about it here.

Finally, we have 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 configuration files, which enabled us to consistently launch the 0x application.

A slightly modified app version, with updated headers and pictures can be found here.

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

A Concluding Note

Migrating Ethereum dApps to Echo, is now a quick and easy task. It opens up new and exciting opportunities, and definitely facilitates global blockchain adoption. Please feel free to leave your comment below if you have any questions and/or suggestions.

ECHO

Blockchain Ecosystem & Smart Contract Protocol

Echo is a blockchain application development platform and network powered by the integration of Bitcoin and smart contracts. The platform enables efficient decentralized applications for Bitcoin and Ethereum with advanced functionality, flexibility, and usability.