evm-token-decimals
यह क्या करती है
यह टूल इस बात का ध्यान रखता है कि अलग-अलग blockchain networks पर digital currency (token) की values सही तरीके से calculate हों। यह उन गलतियों को रोकता है जिनसे values असल से बहुत बड़ी या बहुत छोटी दिखने लगती हैं।
कब इस्तेमाल करें
- ✓जब आप किसी digital currency का balance चेक कर रहे हों।
- ✓जब आप अपनी digital assets की असली पैसों वाली value निकालना चाहते हों।
- ✓जब अलग-अलग blockchain networks पर digital currency की values की तुलना करनी हो।
Skill का लिंक
https://github.com/affaan-m/ECC/blob/main/skills/evm-token-decimals/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“Polygon network पर मेरे wallet में UNI tokens का असली balance कितना है?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह digital currency की सही जानकारी real-time में लाता है और भविष्य में इस्तेमाल के लिए उसे स्टोर कर लेता है। इससे calculations हमेशा सही रहती हैं, भले ही एक ही digital currency अलग-अलग networks पर अलग तरह से दिखती हो।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
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
अक्सर पूछे जाने वाले सवाल
digital currency का balance गलत क्यों दिखता है?
ऐसा इसलिए होता है क्योंकि अलग-अलग blockchain networks एक ही digital currency को दिखाने के लिए अलग संख्या में 'decimal places' इस्तेमाल करते हैं। यह टूल इसी फर्क को ठीक करता है।
digital currencies में 'decimal places' क्या होते हैं?
यह बताता है कि digital currency को कितने छोटे हिस्सों में बांटा गया है। उदाहरण के लिए, 1 Bitcoin को तय 'decimal places' के हिसाब से 1,000,000,000,000,000,000 छोटी इकाइयों में दिखाया जा सकता है।
क्या यह टूल सभी digital currencies के लिए काम करता है?
यह EVM (Ethereum Virtual Machine) networks पर मौजूद digital currencies के लिए बना है, जिनमें Ethereum, Polygon, Binance Smart Chain और दूसरे लोकप्रिय networks शामिल हैं।
जानकारी
लेखक का मूल विवरण
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.
repo: affaan-m/ECC
लोकप्रियता
- GitHub स्टार
- 280k
- रैंकिंग में स्थान
- #312
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
accessibility
280kयह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।
agent-architecture-audit
280kयह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।
agent-eval
280kयह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।
agent-harness-construction
280kयह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।
मिलती-जुलती skills
accelerate
260kआपके एजेंट को Hugging Face Accelerate से कुछ ही अतिरिक्त लाइनों में PyTorch ट्रेनिंग स्क्रिप्ट को कई GPUs पर चलाने में मदद करती है।
evaluating-llms-harness
260kआपके एजेंट को MMLU, GSM8K और HellaSwag जैसे मानक शैक्षणिक टेस्ट पर भाषा मॉडल की जाँच करने और नतीजों की तुलना करने में मदद करती है।
flash-attention
260kआपके एजेंट को transformer मॉडल का attention चरण तेज़ करने और मेमोरी कम करने में मदद करती है, खासकर लंबे इनपुट पर, ट्रेनिंग या inference में।