How to deploy on Evmos: The first EVM chain on Cosmos

Deploying and onboarding users to Evmos

We've covered several Layer 2 sidechains before:


But this time we will do into the exciting new world of Cosmos. Many of the most interesting projects are currently building in the ecosystem and you can expect a lot to happen here in the near future. One of those is Evmos which is more than just a layer 2.

Cosmos Meme

What is the Evmos?

Evmos is a Proof-of-Stake blockchain which will be fully compatible and interoperable with Ethereum. At its core, it's an open-source library called Ethermint and maintained by Tharsis which anyone can use to enable EVM compatibility within a Cosmos chain. Evmos will be it's own Cosmos chain meant as the first of many EVM-compatible chains running in the Cosmos ecosystem.


You can send regular Ethereum transactions to the Evmos Chain. It has implemented a fully functioning EVM on top of the Cosmos SDK

The Cosmos-SDK is an open-source framework for building public Proof-of-Stake as well as permissioned Proof-Of-Authority blockchains. With the Cosmos SDK one can easily create custom blockchains from scratch that can natively interoperate with each other. In fact many projects like we at Injective Protocol are utilizing the power of this SDK already.

The SDK is envisioned as an npm-like framework to build secure blockchain applications on top of Tendermint which is the Cosmos POS consensus algorithm with instant finality fast throughput. SDK-based blockchains are built out of composable modules, most of which are open source and readily available for any developers to use. Anyone can create a module for the Cosmos-SDK, and integrating already-built modules is as simple as importing them into your blockchain application.

This is exactly what Ethermint is enabling. A module which anyone can integrate in their Cosmos chain to enable EVM compatibility. All code for Evmos can be found here and Ethermint here. The testnet for Evmos went live just recently.

Why choose Evmos?

  • High throughput via Tendermint Core

  • Instant finality

  • Decentralization through DAO governance

  • Fully EVM compatible

  • Scalability and connectivity for the Inter Blockchain Communication Protocol (IBC), this means your Dapp will be able to communicate with any Cosmos chain with enabled IBC!

  • Fairer to users with transactions being included on a first in first out (FIFO) fashion

  • Evmos supports all Ethereum Signers up to the latest go-ethereum version (London, Berlin, EIP155, Homestead and Frontier).

How Ethermint enabled the EVM

The addresses are encoded in a different format than in Ethereum using Bech32. You can convert them using the evmosd command line tool. Read below for the details. The transaction itself is run on a fork from geth and since Cosmos SDK has its own concept of gas, the result of gas used from geth after execution is used to overwrite the value from the Cosmos SDK.

For paying the gas costs, as well as staking and governance a native token called Photon will be used. And of course Evmos is compatible with any existing token standards from Ethereum. But keep in mind due to the different consensus mechanism, Evmos has no pending state.

Evmos also supports native multisig accounts thanks to Cosmos SDK.

The whole Cosmos world is exciting, but we are not on cosmosdeveloper.com, so let's get to the Ethereum part.

How to deploy to Evmos

Deploying to the Evmos Chain is straight-forward. If you're using Truffle, simply add the Evmos Chain network configuration like this:

evmos-testnet: {
      provider: () => new HDWalletProvider(mnemonic, 'http://arsiamons.rpc.evmos.org:8545'),
      network_id: 9000,
}

You'll also need funds in the chain of course. For the testnet you can use the faucet here. At the time of this writing this faucet is not working and only the faucet in the Evmos Discord channel is working.

To get your correctly formatted Ethereum address for the faucet, install evmosd: (requires Go 1.17+)

$ git clone https://github.com/tharsis/evmos.git
$ cd evmos
$ make install

Now you can run evmosd and pass your Ethereum address to it:

evmosd debug addr 0x14574A6DFF2DDF9E07828B4345D3040919AF5652
  Address: [20 87 74 109 255 45 223 158 7 130 139 67 69 211 4 9 25 175 86 82]
  Address (hex): 14574A6DFF2DDF9E07828B4345D3040919AF5652
  Bech32 Acc: evmos1z3t55m0l9h0eupuz3dp5t5cypyv674jj7mz2jw
  Bech32 Val: evmosvaloper1z3t55m0l9h0eupuz3dp5t5cypyv674jjn4d6nn

The 'Bech32 Acc' result will be what you need for the faucet.

How to onboard users to your Evmos Dapp

1. Choice of wallet

These days you have much more than just MetaMask as possible wallets to support available. Take a look at Yearn Finance for example. They are supporting 11 different wallets alone at the time of this writing.

Wallet Options

2. MetaMask example live in action

We'll focus on MetaMask as the biggest wallet with the most features. With MetaMask you can nowadays actually request to connect directly to a custom network.

If you want to see this live, check out Pancake Swap as example. Unless you already have Evmos Chain added, it will request to add this network.

3. How to add Evmos automatically for users

You can see on the right how to add the Evmos Chain automatically to the wallet for the user. This will show the popup you see above. If the user confirms, the network is added and automatically switched to.

This is all thanks to EIP-3085 with the new RPC method wallet_addEthereumChain . See also the MetaMask docs here.

const params = [{
    "chainId": "9000",
    "chainName": "Evmos Testnet",
    "rpcUrls": [
        "http://arsiamons.rpc.evmos.org:8545"
    ],
    "nativeCurrency": {
        "name": "Photon",
        "symbol": "PHOTON",
        "decimals": 18
    },
    "blockExplorerUrls": [
        "https://evm.evmos.org"
    ]
}]

try {
    await ethereum.request({
        method: 'wallet_addEthereumChain',
        params,
    })
} catch (error) {
    // something failed, e.g., user denied request
}

How to transfer tokens from other chains to Evmos?

This is currently not yet possible for the testnet, but will be enabled later through two separate mechanisms:

Gravity Bridge

The Gravity bridge is a project enabling ERC-20 transfers from Ethereum to Cosmos and vice-versa.

IBC

IBC is an interoperability protocol for communicating arbitrary data between arbitrary state machines like Cosmos SDK blockchains.

So is this a layer 2 solution for Ethereum? Well as you can see that depends on your perspective. Eventually we will get a place where many chains are connected with each other, sometimes even with shared security through Interchain security or parachains, and calling a chain layer 1, 2 or 3 won't be as clear anymore. On top you have Ethermint which can be used inside any Cosmos based chain.

So yes in a way it's a layer 2 for Ethereum, as well as for the Cosmos chain itself. In another way, it's simply another separate chain on its own.


Markus Waas

Solidity Developer

More great blog posts from Markus Waas

© 2024 Solidity Dev Studio. All rights reserved.

This website is powered by Scrivito, the next generation React CMS.