affaan-m/ECC/docs/ja-JP/skills/evm-token-decimals/SKILL.md
evm-token-decimals
Review evm-token-decimals's use cases, installation, workflow, and original source instructions.
- Source repository stars
- 234,327
- Declared platforms
- 0
- Static risk flags
- 0
- Last source update
- 2026-07-27
- Source checked
- 2026-07-28
Decision brief
What it does—and where it fits
サイレントな小数点不一致は、エラーを発生させることなく残高やUSD値が桁違いになる最も簡単な方法のひとつです。
Not for
- Tasks that require unconfirmed production actions or broad system permissions.
- Environments where the pinned source and install steps cannot be inspected.
Compatibility matrix
Platform support, with evidence labels
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
Inspect first. Install second.
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/evm-token-decimals"Inspect the Agent Skill "evm-token-decimals" from https://github.com/affaan-m/ECC/blob/4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38/docs/ja-JP/skills/evm-token-decimals/SKILL.md at commit 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
What the source asks the agent to do
- 01
使用するタイミング
Python、TypeScript、またはSolidityでERC-20残高を読み取る場合
Python、TypeScript、またはSolidityでERC-20残高を読み取る場合オンチェーン残高から法定通貨の値を計算する場合複数のEVMチェーン間でトークン量を比較する場合 - 02
仕組み
ステーブルコインが同じ小数点を使用していると仮定しないでください。ランタイムでdecimals()を照会し、(chainid, tokenaddress)でキャッシュし、値の計算には小数点安全な数学を使用します。
ステーブルコインが同じ小数点を使用していると仮定しないでください。ランタイムでdecimals()を照会し、(chainid, tokenaddress)でキャッシュし、値の計算には小数点安全な数学を使用します。 - 03
使用例
シンボルが他の場所で通常6小数点を持つからといって1000000をハードコードしないでください。
シンボルが他の場所で通常6小数点を持つからといって1000000をハードコードしないでください。フォールバックをログに記録して可視化しておく。古いまたは非標準トークンはまだ存在します。 - 04
ランタイムで小数点を照会する
シンボルが他の場所で通常6小数点を持つからといって1000000をハードコードしないでください。
シンボルが他の場所で通常6小数点を持つからといって1000000をハードコードしないでください。
Permission review
Static risk signals and limitations
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
Why each signal appears
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 64/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 234,327 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Provenance and original SKILL.md
- Repository
- affaan-m/ECC
- Skill path
- docs/ja-JP/skills/evm-token-decimals/SKILL.md
- Commit
- 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38
- License
- MIT
- Collected
- 2026-07-28
- Default branch
- main
View the original SKILL.md
EVMトークン小数点
サイレントな小数点不一致は、エラーを発生させることなく残高やUSD値が桁違いになる最も簡単な方法のひとつです。
使用するタイミング
- Python、TypeScript、またはSolidityでERC-20残高を読み取る場合
- オンチェーン残高から法定通貨の値を計算する場合
- 複数のEVMチェーン間でトークン量を比較する場合
- ブリッジされた資産を扱う場合
- ポートフォリオトラッカー、ボット、またはアグリゲーターを構築する場合
仕組み
ステーブルコインが同じ小数点を使用していると仮定しないでください。ランタイムでdecimals()を照会し、(chain_id, token_address)でキャッシュし、値の計算には小数点安全な数学を使用します。
使用例
ランタイムで小数点を照会する
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)
シンボルが他の場所で通常6小数点を持つからといって1_000_000をハードコードしないでください。
チェーンとトークンでキャッシュする
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()
特殊なトークンを防御的に処理する
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
フォールバックをログに記録して可視化しておく。古いまたは非標準トークンはまだ存在します。
SolidityでWAD(18小数点)に正規化する
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);
}
ethersを使ったTypeScript
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);
}
クイックなオンチェーン確認
cast call <token_address> "decimals()(uint8)" --rpc-url <rpc>
ルール
- 常にランタイムで
decimals()を照会する - シンボルではなく、チェーンとトークンアドレスでキャッシュする
- floatではなく
Decimal、BigInt、または同等の正確な数学を使用する - ブリッジングやラッパーの変更後は小数点を再照会する
- 比較や価格計算の前に内部会計を一貫して正規化する
Alternatives
Compare before choosing
affaan-m/ECC
evm-token-decimals
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.
affaan-m/ECC
evm-token-decimals
Review evm-token-decimals's use cases, installation, workflow, and original source instructions.