Overview
The Bank precompile provides ERC20-style access to native Cosmos SDK tokens, enabling smart contracts to query balances and token supplies through standardized interfaces. It serves as a Solidity wrapper around the Cosmos SDKx/bank
module.
Address: 0x0000000000000000000000000000000000000804
Related Module: x/bank
Gas Costs
- balances: 2,851 + (2,851 × (n-1)) where n = number of tokens returned
- totalSupply: 2,477 + (2,477 × (n-1)) where n = number of tokens returned
- supplyOf: 2,477
Primary Methods
balances
Signature:balances(address account) → Balance[] memory
Description: Queries all native token balances for a specific account address and returns an array of Balance
(ERC-20 contract address & amount) structures.
account
(address): The account address to query balances for
totalSupply
Signature:totalSupply() → Balance[] memory
Description: Queries the total supply of all native tokens in the system. Returns comprehensive supply information for every token registered in the system.
supplyOf
Signature:supplyOf(address erc20Address) → uint256
Description: Queries the total supply of a specific token by providing its ERC20 contract address. More efficient when you need supply information for a single token.
erc20Address
(address): The ERC20 contract address of the token
Data Structures ->
Balance
The Balance struct represents a token balance with its associated ERC20 contract address:contractAddress
(address): The ERC20 contract address representing the native tokenamount
(uint256): Token amount in the smallest denomination
Full Interface & ABI
Bank Solidity Interface
Bank ABI
Implementation Details
Token Resolution
The precompile resolves native Cosmos SDK denominations to their corresponding ERC-20 contract addresses through thex/erc20
module’s token pair registry. Only tokens with registered token pairs are returned in query results.
Decimal Precision
All amounts returned preserve the original decimal precision stored in thex/bank
module. No decimal conversion is performed by the precompile.
Gas Metering
The precompile implements efficient gas metering by:- Charging base gas for the first result
- Incrementally charging for each additional result in batch queries
- Consuming gas before returning results to prevent DoS vectors
Error Handling
- Invalid token addresses in
supplyOf
return 0 rather than reverting - Queries for accounts with no balances return empty arrays
- All methods are read-only and cannot modify state