Automated summary
This skill explains how to avoid silent decimal-scale bugs when reading, normalizing, and comparing ERC-20 token amounts across multiple EVM chains.
Strengths
- Demonstrates runtime decimals() lookup instead of hardcoded constants, with examples in Python, TypeScript, Solidity, and cast.
- Provides a caching pattern keyed by (chain_id, token_address) that avoids collisions between identical symbols on different chains.
- Covers real edge cases: non-standard tokens whose decimals() reverts, and normalization to 18-decimal WAD for internal accounting.
- Emphasizes exact arithmetic (Decimal, BigInt) over floats for any fiat-value calculation.
Limitations
- Does not cover RPC/provider setup — get_web3_for_chain is referenced but never defined.
- The default fallback of 18 decimals on failure can be wrong for some tokens and comes without a verification strategy.
- Treats post-bridge decimal drift as a rule to follow rather than showing an implementation, and ignores rebasing or fee-on-transfer tokens.
Use it whenever code reads ERC-20 balances, derives fiat values, or compares token amounts across one or more EVM chains.
Skip it for non-EVM ecosystems (Solana, Cosmos) or when the bug is business logic unrelated to amount scaling.
Security analysis
SafeThe skill is purely instructional documentation about querying and normalizing ERC-20 token decimals. It contains no destructive commands, no exfiltration, no obfuscation, and no instructions to disable safety. The only shell example is a standard read-only 'cast call' for querying on-chain data, which is legitimate.
No concerns found
How this analysis is madeExamples
My bot reports a USDC balance on Arbitrum that is 10^12 times too small. Review my balance-reading code and fix the decimal handling so it queries decimals() at runtime and caches per chain and token.Write a TypeScript helper using ethers that reads ERC-20 balances on Ethereum and Polygon, caches decimals by chain_id plus token address, and returns exact decimal strings instead of floats.Check this Solidity function that compares token amounts with different decimals and tell me whether it should normalize to an 18-decimal WAD before pricing.name: evm-token-decimals description: Prevent silent decimal mismatch bugs across EVM chains. Covers runtime decimal lookup, chain-aware caching, bridged-token precision drift, and safe normalization for bots, dashboards, and DeFi tools. Use when handling token amounts across EVM chains, or when a balance, price, or transfer amount is off by orders of magnitude. metadata: version: "1.0.0" origin: ECC direct-port adaptation
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
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
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
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
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
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
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
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/evm-token-decimals-handling-mte1ll3l' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/evm-token-decimals-handling-mte1ll3l/download' --output '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md.part' && mv '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md.part' '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md' && test -s '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/evm-token-decimals' && cp -R '.skill-downloads/evm-token-decimals-handling-mte1ll3l' '.claude/skills/evm-token-decimals'Cursor
test -f '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md' && test -s '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/evm-token-decimals' && cp -R '.skill-downloads/evm-token-decimals-handling-mte1ll3l' '.cursor/skills/evm-token-decimals'Codex
test -f '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md' && test -s '.skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/evm-token-decimals' && cp -R '.skill-downloads/evm-token-decimals-handling-mte1ll3l' '.agents/skills/evm-token-decimals'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/evm-token-decimals-handling-mte1ll3l'openskills read 'evm-token-decimals-handling-mte1ll3l'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/evm-token-decimals-handling-mte1ll3l/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.