This guide is for fresh integration of Cosmos EVM v0.5.0 into new chains. For migration from previous versions, see the specific migration guides.
Prerequisites
- Cosmos SDK v0.53.x based chain
- IBC-Go v10.x
- Go 1.23+
- Understanding of Cosmos SDK module integration
Critical Interface Requirements: v0.5.0 requires implementing specific interfaces (
AppWithPendingTxStream
, evmserver.Application
) with compile-time enforcement. Missing these will cause build failures.Step 1: Dependencies & Imports
Update go.mod
Key Imports for app.go
Key Imports for app.go
Step 2: App Structure Definition
App Struct with Required Fields
App Struct with Required Fields
Required Interface Methods
App Constructor Return Type
Step 3: Store Keys & Module Setup
Store Key Registration
Store Key Registration
Module Registration
Module Registration
Step 4: Keeper Initialization
Why Initialization Order Matters
The keeper initialization order is critical due to dependencies between modules:- PreciseBank must be initialized before EVM keeper as it wraps the bank keeper to provide 18-decimal precision
- FeeMarket must exist before EVM keeper as EVM uses it for gas pricing
- EVM keeper must be initialized before ERC20 keeper due to a forward reference pattern
- ERC20 keeper requires a fully initialized EVM keeper to manage token contracts
Initialization Order (Critical)
Initialization Order (Critical)
Step 5: Ante Handler Integration
Complete Ante Handler Setup
Complete Ante Handler Setup
Call During App Construction
Step 6: Mempool Integration (v0.5.0 Required)
Why Custom Mempool is Required
The standard Cosmos SDK mempool cannot handle Ethereum transactions because:- Nonce ordering: Ethereum requires strict nonce ordering per account
- Gas price dynamics: EIP-1559 transactions use dynamic base fees
- Transaction replacement: Ethereum allows replacing pending transactions with higher gas
- Dual transaction types: Must handle both Cosmos and Ethereum transaction formats
- MetaMask transactions will be rejected
- Nonce gaps will cause transaction failures
- Gas estimation will be incorrect
- Transaction replacement won’t work
Complete Mempool Setup
Complete Mempool Setup
What Happens Without Each Component
Component | Impact if Missing |
---|---|
SetMempool | EVM transactions rejected with “unsupported tx type” |
CheckTxHandler | Transaction validation uses wrong rules, nonce errors |
PrepareProposal | EVM transactions in mempool but never included in blocks |
SignerExtractor | Cannot identify transaction sender, auth failures |
Step 7: Precompile Registration
What Are Precompiles and When Do You Need Them?
Precompiles are special contracts at fixed addresses that provide native Cosmos SDK functionality to EVM smart contracts. They execute native Go code instead of EVM bytecode, offering:- Gas efficiency: 10-100x cheaper than Solidity implementations
- Native integration: Direct access to Cosmos SDK modules
- Atomicity: Operations complete in the same transaction
Decision Tree for Precompiles
If You Need… | Required Precompiles | Optional Precompiles |
---|---|---|
Basic EVM only | None | Bech32, P256 |
DeFi protocols | Bank | Staking, Distribution |
Liquid staking | Bank, Staking | Distribution, Governance |
Cross-chain assets | Bank, ICS20 | ERC20 |
Full Cosmos features | All | Custom precompiles |
Precompile Addresses and Functions
Precompile | Address | Key Functions | Gas Cost |
---|---|---|---|
Bech32 | 0x0000…0100 | Address conversion | ~3,000 |
P256 | 0x0000…0400 | Secp256r1 signatures | ~3,500 |
Bank | 0x0000…0800 | Send, balance queries | ~25,000 |
Staking | 0x0000…0801 | Delegate, undelegate | ~50,000 |
Distribution | 0x0000…0802 | Withdraw rewards | ~30,000 |
ICS20 | 0x0000…0804 | IBC transfers | ~100,000 |
Governance | 0x0000…0805 | Vote, deposit | ~30,000 |
Slashing | 0x0000…0806 | Unjail validator | ~50,000 |
Interface-Based Precompile Setup
Interface-Based Precompile Setup
Step 8: CLI Command Integration
Required CLI Wrapper
Step 9: Configuration Management
Understanding app.toml EVM Parameters
Each parameter controls specific EVM behavior with direct impact on your chain’s operation:app.toml EVM Section
app.toml EVM Section
genesis.json EVM Parameters
genesis.json EVM Parameters
Step 10: Account Configuration
18-Decimal Precision Setup
Coin Type Configuration
Step 11: Testing & Verification
Build Verification
Functionality Testing
Functionality Testing
Configuration Validation
Step 12: Production Considerations
Security Settings
Security Settings
Performance Settings
Performance Settings
Integration Checklist
- Dependencies updated to v0.5.0
- App implements
evmserver.Application
interface -
AppWithPendingTxStream
interface methods implemented - All EVM keepers initialized in correct order
- PreciseBank configured for 18-decimal precision
- Ante handler setup with all v0.5.0 parameters
- Mempool integration with MinTip configuration
- Precompiles registered with interface constructors
- CLI commands use SDK wrapper
- app.toml EVM section configured
- genesis.json parameters set correctly
- Build succeeds without errors
- JSON-RPC functionality verified
- Mempool operations tested
- Precompile calls working