* docs: v0.6.0 changelog (#605) * docs: v0.6.0 changelog * update codeowners * docs: readd banner * update * jobs
5.7 KiB
x/evm
The x/evm
module is responsible for executing Ethereum Virtual Machine (EVM) state transitions.
Usage
-
Import the module and the dependency packages.
import ( "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/tharsis/ethermint/app/ante" ethermint "github.com/tharsis/ethermint/types" "github.com/tharsis/ethermint/x/evm" )
-
Add
AppModuleBasic
to yourModuleBasics
.var ( ModuleBasics = module.NewBasicManager( // ... evm.AppModuleBasic{}, ) )
-
Create the module's parameter subspace in your application constructor.
func NewApp(...) *App { // ... app.subspaces[evm.ModuleName] = app.ParamsKeeper.Subspace(evm.DefaultParamspace) }
-
Define the Ethermint
ProtoAccount
for theAccountKeeper
func NewApp(...) *App { // ... app.AccountKeeper = auth.NewAccountKeeper( cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], ethermint.ProtoAccount, ) }
-
Create the keeper.
func NewApp(...) *App { // ... app.EvmKeeper = evm.NewKeeper( app.cdc, keys[evm.StoreKey], app.subspaces[evm.ModuleName], app.AccountKeeper, ) }
-
Add the
x/evm
module to the app'sModuleManager
.func NewApp(...) *App { // ... app.mm = module.NewManager( // ... evm.NewAppModule(app.EvmKeeper, app.AccountKeeper), // ... ) }
-
Set the
x/evm
moduleBeginBlock
andEndBlock
ordering:app.mm.SetOrderBeginBlockers( evm.ModuleName, ... ) app.mm.SetOrderEndBlockers( evm.ModuleName, ... )
-
Set the
x/evm
module genesis order. The module must go after theauth
andbank
modules.func NewApp(...) *App { // ... app.mm.SetOrderInitGenesis(auth.ModuleName, bank.ModuleName, ... , evm.ModuleName, ...) }
-
Set the Ethermint
AnteHandler
to support EVM transactions. Note, the defaultAnteHandler
provided by thex/evm
module depends on thex/auth
andx/supply
modules.func NewApp(...) *App { // ... app.SetAnteHandler(ante.NewAnteHandler( app.AccountKeeper, app.EvmKeeper, app.SupplyKeeper )) }
Genesis
The x/evm
module defines its genesis state as follows:
type GenesisState struct {
Accounts []GenesisAccount `json:"accounts"`
TxsLogs []TransactionLogs `json:"txs_logs"`
ChainConfig ChainConfig `json:"chain_config"`
Params Params `json:"params"`
}
Which relies on the following types:
type GenesisAccount struct {
Address string `json:"address"`
Balance sdk.Int `json:"balance"`
Code hexutil.Bytes `json:"code,omitempty"`
Storage Storage `json:"storage,omitempty"`
}
type TransactionLogs struct {
Hash common.Hash `json:"hash"`
Logs []*ethtypes.Log `json:"logs"`
}
type ChainConfig struct {
HomesteadBlock sdk.Int `json:"homestead_block" yaml:"homestead_block"` // Homestead switch block (< 0 no fork, 0 = already homestead)
DAOForkBlock sdk.Int `json:"dao_fork_block" yaml:"dao_fork_block"` // TheDAO hard-fork switch block (< 0 no fork)
DAOForkSupport bool `json:"dao_fork_support" yaml:"dao_fork_support"` // Whether the nodes supports or opposes the DAO hard-fork
// EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150)
EIP150Block sdk.Int `json:"eip150_block" yaml:"eip150_block"` // EIP150 HF block (< 0 no fork)
EIP150Hash string `json:"eip150_hash" yaml:"eip150_hash"` // EIP150 HF hash (needed for header only clients as only gas pricing changed)
EIP155Block sdk.Int `json:"eip155_block" yaml:"eip155_block"` // EIP155 HF block
EIP158Block sdk.Int `json:"eip158_block" yaml:"eip158_block"` // EIP158 HF block
ByzantiumBlock sdk.Int `json:"byzantium_block" yaml:"byzantium_block"` // Byzantium switch block (< 0 no fork, 0 = already on byzantium)
ConstantinopleBlock sdk.Int `json:"constantinople_block" yaml:"constantinople_block"` // Constantinople switch block (< 0 no fork, 0 = already activated)
PetersburgBlock sdk.Int `json:"petersburg_block" yaml:"petersburg_block"` // Petersburg switch block (< 0 same as Constantinople)
IstanbulBlock sdk.Int `json:"istanbul_block" yaml:"istanbul_block"` // Istanbul switch block (< 0 no fork, 0 = already on istanbul)
MuirGlacierBlock sdk.Int `json:"muir_glacier_block" yaml:"muir_glacier_block"` // Eip-2384 (bomb delay) switch block (< 0 no fork, 0 = already activated)
YoloV2Block sdk.Int `json:"yoloV2_block" yaml:"yoloV2_block"` // YOLO v1: https://github.com/ethereum/EIPs/pull/2657 (Ephemeral testnet)
EWASMBlock sdk.Int `json:"ewasm_block" yaml:"ewasm_block"` // EWASM switch block (< 0 no fork, 0 = already activated)
}
type Params struct {
// EVMDenom defines the token denomination used for state transitions on the
// EVM module.
EvmDenom string `json:"evm_denom" yaml:"evm_denom"`
// EnableCreate toggles state transitions that use the vm.Create function
EnableCreate bool `json:"enable_create" yaml:"enable_create"`
// EnableCall toggles state transitions that use the vm.Call function
EnableCall bool `json:"enable_call" yaml:"enable_call"`
// ExtraEIPs defines the additional EIPs for the vm.Config
ExtraEIPs []int `json:"extra_eips" yaml:"extra_eips"`
}
Client
JSON-RPC
See the Ethermint JSON-RPC docs for reference.
Documentation and Specification
- Ethermint documentation: https://evmos.dev