Overview
The ERC20 precompile provides a standard ERC20-compliant interface that allows EVM tooling and libraries to interact with native Cosmos SDK tokens stored in the bank module as if they were standard ERC20 tokens. Each registered token pair gets its own unique precompile contract address that directly interfaces with the bank module - no token conversion or wrapping occurs. All balances, transfers, and operations work directly on the native bank module token balances. Address: Dynamic (assigned per token pair registration) Related Module: x/erc20Gas Costs
Gas costs are approximated and may vary based on token complexity and chain settings.
Method | Gas Cost |
---|---|
name() | ~3,000 gas |
symbol() | ~3,000 gas |
decimals() | ~2,000 gas |
totalSupply() | ~2,500 gas |
balanceOf(address) | ~2,900 gas |
allowance(address,address) | ~3,000 gas |
transfer(address,uint256) | ~35,000 gas |
transferFrom(address,address,uint256) | ~40,000 gas |
approve(address,uint256) | ~30,000 gas |
increaseAllowance(address,uint256) | ~30,500 gas |
decreaseAllowance(address,uint256) | ~30,500 gas |
Token Pair Registration
The ERC20 precompile works through a token pair registration system:- Native Cosmos Token: Each Cosmos SDK denomination (e.g.,
test
,atest
) exists as a native token in the bank module - ERC20 Interface: A corresponding ERC20 precompile contract provides an interface at a unique address
- Direct Bank Module Access: The ERC20 interface operates directly on bank module balances - there is no separate ERC20 token state
- Dynamic Addresses: Each token pair gets its own precompile address when registered
The precompile address is deterministically generated based on the token denomination. Query the x/erc20 module to find the precompile address for a specific token.
Methods
totalSupply
Returns the total amount of tokens in existence.
balanceOf
Returns the token balance of a specified account.
transfer
Moves tokens from the caller’s account to a recipient.
transferFrom
Moves tokens from one account to another using an allowance.
approve
Sets the allowance of a spender over the caller’s tokens.
allowance
Returns the remaining number of tokens that a spender is allowed to spend on behalf of an owner.
name
Returns the name of the token.
symbol
Returns the symbol of the token.
decimals
Returns the number of decimals used for the token.
Decimal Handling: The ERC20 precompile may need to handle complex decimal conversions between Cosmos native tokens and ERC20 representation. Some Cosmos tokens use 6 decimals (e.g.,
test
) while ERC20 typically uses 18. Always verify the decimal count for accurate amount calculations.Full Solidity Interface & ABI
ERC20 Solidity Interface
ERC20 ABI