Overview
The ERC20 precompile provides standard ERC20 token functionality for native Cosmos tokens that have been registered for EVM compatibility. Each registered token pair gets its own unique precompile contract address. This allows for seamless interaction with native Cosmos assets through familiar ERC20 interfaces. 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 Mapping
The ERC20 precompile works through a token pair mapping system:- Native Cosmos Token: Each Cosmos SDK denomination (e.g.,
test
,stake
) exists as a native token - ERC20 Contract: A corresponding ERC20 precompile contract is created at a unique address
- Bidirectional Conversion: Tokens can be converted between native and ERC20 representations
- 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