Skip to main content

How EVM Communicates with Cosmos

The EVM communicates with the Cosmos part of the chain through precompiles - Go code that directly interacts with other module states (e.g., Bank module). Precompiles are special contract addresses that execute native Go code instead of EVM bytecode, enabling seamless integration between EVM and Cosmos SDK modules.

Cosmos SDK Precompiles

There are 5 Cosmos SDK precompiles exposed inside the EVM:

1. Staking Precompile

Interact with the staking module directly from EVM contracts:
  • Delegate tokens: Delegate native tokens to validators
  • Undelegate tokens: Undelegate from validators
  • Redelegate tokens: Move delegation between validators
  • Query delegation information: Get delegation details
Use Cases:
  • Automated staking strategies
  • Liquid staking protocols
  • Validator selection algorithms

2. Distribution Precompile

Manage staking rewards from EVM contracts:
  • Claim rewards: Claim staking rewards
  • Withdraw rewards: Withdraw accumulated rewards
  • Query reward information: Get reward details
Use Cases:
  • Automated reward claiming
  • Reward distribution protocols
  • Staking aggregators

3. Slashing Precompile

Handle slashing operations and re-staking:
  • Re-staking operations: Manage validator re-staking
  • Reward management: Handle slashing-related rewards
  • Validator penalties: Query and handle penalties
Use Cases:
  • Slashing protection protocols
  • Validator health monitoring
  • Risk management systems

4. Governance Precompile

Participate in on-chain governance from EVM contracts:
  • Vote on proposals: Cast votes on governance proposals
  • Create proposals: Submit new governance proposals
  • Query proposal information: Get proposal details and status
Use Cases:
  • Automated governance participation
  • Governance aggregators
  • Proposal creation tools

5. Bank Precompile

Transfer native Cosmos tokens from EVM contracts:
  • Transfer tokens: Send native tokens
  • Query balances: Get token balances
  • Multi-send operations: Batch token transfers
Use Cases:
  • Token bridges
  • Payment protocols
  • Multi-sig wallets

ERC20 Precompiles

Each TokenFactory token has its own ERC20 precompile address, allowing:
  • Control token balance: Manage token balances from EVM
  • Transfer tokens: Transfer TokenFactory tokens
  • Use tokens in EVM contracts: Seamless integration
This enables TokenFactory tokens (created via Cosmos SDK) to be used directly in EVM contracts without wrapping.

Using Precompiles

Precompiles are called like regular contract calls in Solidity:
// Example: Calling a precompile
// (Addresses and interfaces are examples - actual addresses will be documented)

interface IStakingPrecompile {
    function delegate(address validator, uint256 amount) external;
}

contract MyContract {
    address constant STAKING_PRECOMPILE = 0x0000000000000000000000000000000000000800;
    
    function stake(address validator, uint256 amount) external {
        IStakingPrecompile(STAKING_PRECOMPILE).delegate(validator, amount);
    }
}

Precompile Addresses

Precompile addresses are fixed and documented. See Using Precompiles for detailed addresses and interfaces.

Benefits of Precompiles

  1. Direct Cosmos Integration: Access Cosmos SDK features from EVM
  2. No Wrapping Required: Use native Cosmos tokens directly
  3. Atomic Operations: Precompile calls are part of the transaction
  4. Gas Efficient: Native Go code execution is more efficient than contract calls

Next Steps