Note

Deploy a Contract on Evmos

Evmos is a evm-compatible side chain built using cosmos. It’s a application-agnostic chain that is interoperable with the Ethereum Mainnet, EVM-compatible environments, and other BFT chains via IBC — making it easy for users and developers to move value between chains and also provide lower transaction fees.

This article will tell you how to deploy a smart contract on evmos and check it using blockchain explorers.

get some fake money

https://faucet.evmos.dev/

deploy a demo smart contract using remix

the demo contract:

https://github.com/Fooooooooooox/zksync_contract_test/blob/main/contracts/test_contracts.sol

[block:1590458 txIndex:0]from: 0xca1...Ef7b4to: MyToken.(constructor)value: 0 weidata: 0x608...36f6elogs: 1hash: 0xb57...81e30
status true Transaction mined and execution succeed
transaction hash 0x98b72ecbddd4d541e1be6a6510317639c35ed4147d816cdae38bf03de6f77977
from 0xca1ED14df2AD33bAfb18cAd6b8A0E2a33e1Ef7b4
to MyToken.(constructor)
gas 4125448 gas
transaction cost 4125448 gas
input 0x608...36f6e
decoded input {}
decoded output -
logs [
{
"from": "0x3c8901be7f922F6c31E53c4E456b9D61AAc0d31B",
"topic": "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
"event": "OwnershipTransferred",
"args": {
"0": "0x0000000000000000000000000000000000000000",
"1": "0xca1ED14df2AD33bAfb18cAd6b8A0E2a33e1Ef7b4",
"previousOwner": "0x0000000000000000000000000000000000000000",
"newOwner": "0xca1ED14df2AD33bAfb18cAd6b8A0E2a33e1Ef7b4"
}
}
]
val 0 wei
>

Logs includes some extra information(like contract iteration call)

This this a deploy transaction, but actually it implicitly generated another transaction: OwnershipTransferred

Why?

Because i use the openzepplin modifier: Ownable

contract MyToken is ERC1155, Ownable {
...
}

You can check the modifier here:

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol

There is a transferOwnership function inside:

function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}

Related Knowledge

The process of deploying a new contract(from geth source code view

evm.Create is used to deploy a new contract

func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
contractAddr = crypto.CreateAddress(
caller.Address(), evm.StateDB.GetNonce(caller.Address()))
return evm.create(caller, &codeAndHash{code: code}, gas, value, contractAddr)
}
func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *big.Int, address common.Address) ([]byte, common.Address, uint64, error) {
...
contract := NewContract(caller, AccountRef(address), value, gas)
contract.SetCodeOptionalHash(&address, codeAndHash)
...
}
  1. generate a contract address using the deployer’s address and nonce
  2. set the code(abi) and code hash in the the storage trie of that contract address

Check It on Blockchain Explorers

Create transaction:

https://evm.evmos.dev/tx/0x98b72ecbddd4d541e1be6a6510317639c35ed4147d816cdae38bf03de6f77977/internal-transactions

Contract:

https://evm.evmos.dev/address/0x3c8901be7f922F6c31E53c4E456b9D61AAc0d31B/transactions

0
0
...
...
...
Avatar