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.
Detected risks:
This skill is designed to eliminate silent and often costly errors caused by incorrect handling of ERC-20 token decimals across EVM-compatible blockchains. In many DeFi and blockchain applications, developers mistakenly assume a fixed decimal precision for tokens, which can lead to balances, pricing, and portfolio valuations being off by orders of magnitude without any runtime errors. This issue becomes even more complex in cross-chain environments where the same token symbol may have different decimal configurations depending on the chain or bridged representation.
The skill focuses on enforcing safe and accurate decimal handling by requiring runtime retrieval of the `decimals()` value directly from the token contract. It supports caching strategies keyed by `(chain_id, token_address)` to reduce redundant on-chain calls while maintaining correctness. It also encourages defensive programming practices such as fallback handling when `decimals()` is unavailable, and the use of precise numeric types like `Decimal` or `BigInt` instead of floating-point arithmetic. Additionally, it provides normalization strategies for converting token amounts into a consistent 18-decimal WAD format, making internal accounting and comparisons reliable across heterogeneous assets and chains.
This skill is primarily intended for developers building DeFi protocols, trading bots, portfolio trackers, analytics dashboards, or any system that aggregates or compares token balances across multiple environments. It is especially useful in cross-chain applications and systems dealing with bridged assets, where decimal inconsistencies are common. By standardizing decimal handling practices, it helps ensure correctness in financial calculations and prevents subtle bugs that could otherwise lead to significant valuation errors.
Hardcoding decimals can lead to incorrect balance and price calculations because different tokens—even those with the same symbol—may use different decimal configurations across chains or bridged versions. This can silently produce errors without any runtime warnings.
If a token's `decimals()` call fails or reverts, the skill recommends using a defensive fallback (commonly 18 decimals) while logging the incident. This ensures the application continues functioning while making the issue visible for debugging.
Yes, caching is safe and recommended as long as it is keyed by both `chain_id` and `token_address`. This prevents cross-chain or cross-token collisions while reducing repeated on-chain calls for the same asset.
The skill recommends using exact numeric representations such as `Decimal` in Python or `BigInt` in JavaScript/TypeScript to avoid precision loss. Floating-point types should be avoided entirely.
Quick Setup:
.claude/skills/Repository
affaan-m/everything-claude-code