
Evm Token Decimals
Normalize ERC-20 balances and fiat values by querying on-chain decimals at runtime instead of hard-coding 6 or 18 decimals per chain.
Overview
EVM Token Decimals is an agent skill for the Build phase that prevents silent ERC-20 decimal mismatches by querying on-chain decimals and normalizing balances for bots, dashboards, and DeFi tools.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill evm-token-decimalsWhat is this skill?
- Query ERC-20 decimals() at runtime with cache keyed by (chain_id, token_address)
- Covers Python, TypeScript, and Solidity examples for balance reads
- Addresses bridged-token precision drift across EVM chains
- Uses decimal-safe math to avoid silent orders-of-magnitude errors
- Applies to portfolio trackers, bots, and aggregators comparing amounts cross-chain
- Runtime cache key (chain_id, token_address)
- Covers Python, TypeScript, and Solidity patterns
Adoption & trust: 3k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You read token balances from chain but values look plausible while being wrong by orders of magnitude because decimals differ per chain and bridged token.
Who is it for?
Solo builders adding ERC-20 balance or USD valuation logic to bots, dashboards, or aggregators on multiple EVM chains.
Skip if: Teams only editing Solidity with fixed local decimals and no cross-chain or bridged-asset reads.
When should I use this skill?
Reading ERC-20 balances, calculating fiat values, comparing amounts across EVM chains, or handling bridged assets in bots and dashboards.
What do I get? / Deliverables
Balances and fiat conversions use runtime decimals with chain-aware caching and safe normalization so comparisons across EVM networks stay accurate.
- Decimal-safe balance helpers
- Chain-aware decimal cache usage in integration code
Recommended Skills
Journey fit
Decimal-safe token math is implemented while wiring on-chain reads into bots, dashboards, and DeFi backends during the build phase. The skill governs contract calls, caching, and normalization when integrating Web3 libraries with trading or portfolio code.
How it compares
Use instead of hard-coding 6/18 decimals or copying one mainnet assumption onto L2s and bridges.
Common Questions / FAQ
Who is evm-token-decimals for?
Indie developers and agent users shipping DeFi-adjacent backends, trading bots, or portfolio tools that read ERC-20 balances in Python, TypeScript, or Solidity.
When should I use evm-token-decimals?
Use it during Build when integrating Web3 reads, calculating fiat from on-chain balances, handling bridged assets, or comparing token amounts across chains.
Is evm-token-decimals safe to install?
Review the Security Audits panel on this Prism page and your org policy before enabling any third-party skill; the skill describes on-chain view calls and local decimal math, not custody of keys.
SKILL.md
READMESKILL.md - Evm Token Decimals
# EVM Token Decimals Silent decimal mismatches are one of the easiest ways to ship balances or USD values that are off by orders of magnitude without throwing an error. ## When to Use - Reading ERC-20 balances in Python, TypeScript, or Solidity - Calculating fiat values from on-chain balances - Comparing token amounts across multiple EVM chains - Handling bridged assets - Building portfolio trackers, bots, or aggregators ## How It Works Never assume stablecoins use the same decimals everywhere. Query `decimals()` at runtime, cache by `(chain_id, token_address)`, and use decimal-safe math for value calculations. ## Examples ### Query decimals at runtime ```python from decimal import Decimal from web3 import Web3 ERC20_ABI = [ {"name": "decimals", "type": "function", "inputs": [], "outputs": [{"type": "uint8"}], "stateMutability": "view"}, {"name": "balanceOf", "type": "function", "inputs": [{"name": "account", "type": "address"}], "outputs": [{"type": "uint256"}], "stateMutability": "view"}, ] def get_token_balance(w3: Web3, token_address: str, wallet: str) -> Decimal: contract = w3.eth.contract( address=Web3.to_checksum_address(token_address), abi=ERC20_ABI, ) decimals = contract.functions.decimals().call() raw = contract.functions.balanceOf(Web3.to_checksum_address(wallet)).call() return Decimal(raw) / Decimal(10 ** decimals) ``` Do not hardcode `1_000_000` because a symbol usually has 6 decimals somewhere else. ### Cache by chain and token ```python from functools import lru_cache @lru_cache(maxsize=512) def get_decimals(chain_id: int, token_address: str) -> int: w3 = get_web3_for_chain(chain_id) contract = w3.eth.contract( address=Web3.to_checksum_address(token_address), abi=ERC20_ABI, ) return contract.functions.decimals().call() ``` ### Handle odd tokens defensively ```python try: decimals = contract.functions.decimals().call() except Exception: logging.warning( "decimals() reverted on %s (chain %s), defaulting to 18", token_address, chain_id, ) decimals = 18 ``` Log the fallback and keep it visible. Old or non-standard tokens still exist. ### Normalize to 18-decimal WAD in Solidity ```solidity interface IERC20Metadata { function decimals() external view returns (uint8); } function normalizeToWad(address token, uint256 amount) internal view returns (uint256) { uint8 d = IERC20Metadata(token).decimals(); if (d == 18) return amount; if (d < 18) return amount * 10 ** (18 - d); return amount / 10 ** (d - 18); } ``` ### TypeScript with ethers ```typescript import { Contract, formatUnits } from 'ethers'; const ERC20_ABI = [ 'function decimals() view returns (uint8)', 'function balanceOf(address) view returns (uint256)', ]; async function getBalance(provider: any, tokenAddress: string, wallet: string): Promise<string> { const token = new Contract(tokenAddress, ERC20_ABI, provider); const [decimals, raw] = await Promise.all([ token.decimals(), token.balanceOf(wallet), ]); return formatUnits(raw, decimals); } ``` ### Quick on-chain check ```bash cast call <token_address> "decimals()(uint8)" --rpc-url <rpc> ``` ## Rules - Always query `decimals()` at runtime - Cache by chain plus token address, not symbol - Use `Decimal`, `BigInt`, or equivalent exact math, not float - Re-query decimals after bridging or wrapper changes - Normalize internal accounting consistently before comparison or pricing