SKILL

evm-token-decimals

Prevents silent decimal mismatch errors across EVM chains. Covers runtime decimal lookup, chain-aware caching, bridged token precision drift, and safe normalization for bots, dashboards, and DeFi tools.

Machine translation
Read the original Chinese text

防止跨EVM链的静默小数不匹配错误。涵盖运行时小数查找、链感知缓存、桥接代币精度漂移以及面向机器人、仪表盘和DeFi工具的安全归一化。

Target: Target not categorized. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original Chinese text

Topics in the source

  • EVM 代币精度
  • 适用场景
  • 工作原理
  • 示例
  • 运行时查询精度
  • 按链和代币缓存
  • 防御性处理异常代币
  • 在 Solidity 中归一化为 18 位 WAD 精度

静默的精度不匹配是导致余额或美元价值出现数量级偏差且不抛出错误的最常见原因之一。 在 Python、TypeScript 或 Solidity 中读取 ERC-20 余额 根据链上余额计算法币价值 跨多条 EVM 链比较代币数量 处理跨链桥接资产 构建投资组合追踪器、机器人或聚合器 切勿假设稳定币在所有链上使用相同的精度。在运行时查询 decimals(),按 (chainid, tokenaddress) 进行缓存,并使用精度安全的数学运算进行价值计算。 不要硬编码 1000000,因为同名代币在其他链上通常有 6 位小数。 记录回退值并保持可见。旧版或非标准代币仍然存在。 始终在运行时查询 decimals() 按链加代币地址进行缓存,而非按代币符号 使用 Decimal、BigInt 或等效的精确数学运算,避免使用浮点数 在跨链桥接或代币包装变更后重新查询精度 在比较或定价前,始终将内部记账归一化为一致精度

Source repository
affaan-m/ECC
Source file
docs/zh-CN/skills/evm-token-decimals/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:50.383Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.