evm-token-decimals

Query and normalize ERC-20 token decimals across EVM chains at runtime.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill evm-token-decimals-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: evm-token-decimals
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/evm-token-decimals
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill evm-token-decimals-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires web3, ethers.

What problem does it solve? Hardcoded token decimal assumptions cause silent balance and USD value errors that are off by orders of magnitude without throwing exceptions, especially when the same token symbol has different decimals on different chains or after bridging. ## Core Features & Use Cases - Runtime Decimal Lookup: Query decimals() on-chain in Python (web3), TypeScript (ethers), or Solidity instead of hardcoding values like 6 or 18. - Chain-Aware Caching: Cache decimals keyed by (chain_id, token_address) rather than symbol, with defensive fallback handling for non-standard tokens that revert. - Safe Normalization: Convert token amounts to 18-decimal WAD in Solidity and use Decimal/BigInt exact math for fiat value calculations. - Use Case: A portfolio tracker aggregating USDC balances across Ethereum, Polygon, and Arbitrum queries each token's decimals per chain, caches the results, and computes USD values without precision drift. ## Quick Start Use the evm-token-decimals skill to safely read and normalize an ERC-20 token balance for a wallet address on a given chain.

Frequently Asked Questions about evm-token-decimals

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get ERC-20 token decimals in Python?▼

Call the token contract's decimals() function via web3.py using a minimal ERC-20 ABI, then divide the raw balanceOf result by 10 ** decimals using Decimal for exact math. Never hardcode decimal values based on the token symbol.

How to read token balances with ethers.js?▼

Create a Contract instance with an ABI containing decimals() and balanceOf(), call both in parallel with Promise.all, then use formatUnits(raw, decimals) to convert the raw uint256 into a human-readable string.

Why do token balances show wrong values across chains?▼

The same token symbol can use different decimals on different chains, and bridged or wrapped tokens may change precision. Cache decimals by (chain_id, token_address) and re-query after bridging instead of assuming a fixed value.

What happens when decimals() reverts on a token contract?▼

Some old or non-standard tokens revert on decimals(). Catch the exception, log a visible warning with the token address and chain ID, and fall back to 18 decimals as a defensive default.

How do I normalize token amounts in Solidity?▼

Read the token's decimals via IERC20Metadata, then scale the amount to 18-decimal WAD by multiplying by 10 ** (18 - d) when d < 18 or dividing when d > 18. This keeps internal accounting consistent before pricing or comparison.