Agent skill · software engineering · affaan-m
evm-token-decimals
防止跨EVM链的静默小数不匹配错误。涵盖运行时小数查找、链感知缓存、桥接代币精度漂移以及面向机器人、仪表盘和DeFi工具的安全归一化。
Why this skill is useful
Provides domain-specific knowledge on handling ERC-20 token decimals across EVM chains, including caching strategies and error handling that the AI wouldn't reliably generate on its own.
What it needs
Requires ethers, web3 installed locally. About 1k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
EVM 代币精度 静默的精度不匹配是导致余额或美元价值出现数量级偏差且不抛出错误的最常见原因之一。 适用场景 在 Python、TypeScript 或 Solidity 中读取 ERC-20 余额 根据链上余额计算法币价值 跨多条 EVM 链比较代币数量 处理跨链桥接资产 构建投资组合追踪器、机器人或聚合器 工作原理 切勿假设稳定币在所有链上使用相同的精度。在运行时查询 decimals(),按 (chainid, tokenaddress) 进行缓存,并使用精度安全的数学运算进行价值计算。 示例 运行时查询精度 不要硬编码 1000000,因为同名代币在其他链上通常有 6 位小数。 按链和代币缓存 防御性处理异常代币 记录回退值并保持可见。旧版或非标准代币仍然存在。 在 Solidity 中归一化为 18 位 WAD 精度 使用 ethers 的 TypeScript 示例 快速链上检查 规则 始终在运行时查询 decimals() 按链加代币地址进行缓存,而非按代币符号 使用 Decimal、BigInt 或等效的精确数学运算,避免使用浮点数 在跨链桥接或代币包装变更后重新查询精度 在比较或定价前,始终将内部记账归一化为一致精度
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/evm-token-decimals--65973b