solidity-debug
??ンチェーンでのトランザクションが失敗した際に、その原因を特定し、レシート分析、ガス診断、リバート理由の抽出、状態検証などを用いてデバッグを支援するSkillです。
📜 元の英語説明(参考)
[AUTO-INVOKE] MUST be invoked when debugging failed on-chain transactions. Covers transaction receipt analysis, gas diagnosis, calldata decoding, revert reason extraction, and state verification using cast. Trigger: any task involving failed tx analysis, revert debugging, or on-chain transaction troubleshooting.
🇯🇵 日本人クリエイター向け解説
??ンチェーンでのトランザクションが失敗した際に、その原因を特定し、レシート分析、ガス診断、リバート理由の抽出、状態検証などを用いてデバッグを支援するSkillです。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o solidity-debug.zip https://jpskill.com/download/5972.zip && unzip -o solidity-debug.zip && rm solidity-debug.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5972.zip -OutFile "$d\solidity-debug.zip"; Expand-Archive "$d\solidity-debug.zip" -DestinationPath $d -Force; ri "$d\solidity-debug.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
solidity-debug.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
solidity-debugフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
失敗したトランザクションのデバッグワークフロー (cast)
言語ルール
- ユーザーが使用している言語と常に同じ言語で応答してください。 ユーザーが中国語で質問した場合は中国語で、英語で質問した場合は英語で応答してください。
ステップ 1: トランザクションレシートの取得 — 成功/失敗の判断
source .env
cast receipt <tx_hash> --rpc-url $RPC_URL
注目フィールド:
| フィールド | 意味 |
|---|---|
status |
0 = 失敗, 1 = 成功 |
gasUsed |
実際に消費された gas |
logs |
空の配列 [] = トランザクションが revert し、イベントが発行されていない |
to |
ターゲットコントラクトアドレス |
ステップ 2: トランザクション詳細の取得 — gas limit と input の取得
cast tx <tx_hash> --rpc-url $RPC_URL
注目フィールド:
| フィールド | 意味 |
|---|---|
gas |
送信者が設定した gas limit |
input |
呼び出された calldata(関数セレクター + パラメーターエンコーディング) |
from / to |
送信者とターゲットコントラクト |
value |
送信されたネイティブトークンの量 |
ステップ 3: 失敗タイプの判断 — gasUsed vs gas limit
| 現象 | 判断 | 解決方向 |
|---|---|---|
| gasUsed / gas ≈ 100%(例: 999,472 / 1,000,000) | Out of Gas (OOG) | gas limit を増やすか、eth_estimateGas を使用する |
| gasUsed が gas limit を大幅に下回る(例: 50,000 / 1,000,000) | Revert | revert reason を取得する必要があります。ステップ 6 を参照してください |
| gasUsed は正常だが status=0 | 内部呼び出しの失敗 | 残高、承認、内部 call の戻り値を確認する |
| トランザクションがそもそもオンチェーンにない | Nonce/Gas Price の問題 | pending キューを確認する |
ステップ 4: 関数セレクターのデコード — どの関数が呼び出されたかを確認
# input の最初の 4 バイトから関数シグネチャを検索
cast 4byte 0xb51a038a
# 出力例: unstake(uint256,address[],uint256[])
ステップ 5: 完全な calldata のデコード — 呼び出しパラメーターの復元
# ステップ 4 で得られた関数シグネチャを使用してデコード
cast calldata-decode "unstake(uint256,address[],uint256[])" <完全なinput_data>
デコードされたパラメーターは以下に使用できます:
- 入力パラメーターに誤りがないか分析する
- トランザクションの再試行に直接使用する
ステップ 6: Revert Reason の取得(OOG 以外のシナリオ)
# 方法 A: cast call シミュレーション(失敗したブロック番号を指定し、トランザクションが存在するブロックを使用)
cast call <to> <input_data> \
--from <from> \
--block-number <block_number> \
--rpc-url $RPC_URL
# 方法 B: cast run でトランザクションをリプレイ(アーカイブノードが必要)
cast run <tx_hash> --rpc-url <archive_rpc_url>
# 方法 C: オンラインツール(予備)
# Tenderly や Blocksec Phalcon などのトランザクション分析プラットフォームを使用
ステップ 7: オンチェーン状態のクエリ — トランザクション失敗後のデータがロールバックされたことを確認
# public 変数/マッピングをクエリ
cast call <contract> "orderLocations(uint256)(address,uint256,bool)" <id> --rpc-url $RPC_URL
# struct フィールドをクエリ(ABI の順序で戻り値を指定)
cast call <contract> "userStakeRecord(address,uint256)(uint40,uint160,bool,uint8,uint256)" <user> <index> --rpc-url $RPC_URL
失敗したトランザクションの状態変更は完全にロールバックされます。データが元の状態にあることを確認する必要があります。
ステップ 8: 成功したトランザクションと失敗したトランザクションの比較 — 差異の特定
成功したトランザクションと失敗したトランザクションを並べて比較します:
| 比較軸 | 説明 |
|---|---|
| gas 消費 | OOG かどうかを判断 |
| 呼び出しパラメーター | 入力パラメーターの問題かどうかを判断 |
| ターゲットアドレス | 間違ったコントラクトを呼び出したかどうかを判断 |
| ブロック時間 | タイムロックなどの制限があるかどうかを判断 |
| コントラクト状態 | 前提条件が満たされていないかどうかを判断 |
ステップ 9: トランザクションの再試行
source .env
# gas limit を指定しない(ノードに自動見積もりさせる、推奨)
cast send <contract> "functionName(uint256,address[],uint256[])" <arg1> "[<addr1>,<addr2>]" "[<amt1>,<amt2>]" \
--account <KEYSTORE_NAME> \
--rpc-url $RPC_URL \
--legacy
# 高い gas limit を指定する(消費範囲が既知のシナリオに適用)
cast send <contract> "functionName(uint256)" <arg1> \
--account <KEYSTORE_NAME> \
--rpc-url $RPC_URL \
--gas-limit 2000000 \
--legacy
セキュリティに関する注意事項
| ルール | 説明 |
|---|---|
| 秘密鍵の管理 | 秘密鍵の管理には Foundry Keystore (--account) を使用し、コマンドで平文で渡すことは禁止されています |
| シミュレーション優先 | 実際に送信する前に cast call でシミュレーションし、revert しないことを確認します |
| 1件ずつ送信 | バッチ再試行の際は、まず1件送信して検証し、成功したら残りを送信します |
| 状態確認 | 送信後、cast receipt で status=1 であることを確認し、さらに cast call でオンチェーンの状態が変更されたことを確認します |
完全なサンプルプロセス
source .env
# 1. レシートを確認
cast receipt 0x4ca1...414f --rpc-url $RPC_URL
# 2. トランザクション詳細を確認
cast tx 0x4ca1...414f --rpc-url $RPC_URL
# 3. gas=1000000, gasUsed=999472, status=0 → OOG であることを発見
# 4. 関数セレクターをデコード
cast 4byte 0xb51a038a
# → unstake(uint256,address[],uint256[])
# 5. 完全なパラメーターをデコード
cast calldata-decode "unstake(uint256,address[],uint256[])" 0xb51a038a...
# 6. シミュレーションで通過することを確認
cast call <contract> "unstake(uint256,address[],uint256[])" 35 "[addr1,addr2]" "[amt1,amt2]" \
--from <from> --rpc-url $RPC_URL
# 7. オンチェーン状態をクエリして、注文がまだ処理されていないことを確認
cast call <contract> "orderLocations(uint256)(address,uint256,bool)" 35 --rpc-url $RPC_URL
# 8. OOG であることを確認 → gas を制限せずに再試行
cast send <contract> "unstake(uint256,address[],uint256[])" 35 "[addr1,addr2]" "[amt1,amt2]" \
--account <KEYSTORE_NAME> --rpc-url $RPC_URL --legacy
# 9. 成功を確認
cast receipt <new_tx_hash> --rpc-url $RPC_URL 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Failed Transaction Debug Workflow (cast)
Language Rule
- Always respond in the same language the user is using. If the user asks in Chinese, respond in Chinese. If in English, respond in English.
Step 1: 获取交易回执 — 判断成功/失败
source .env
cast receipt <tx_hash> --rpc-url $RPC_URL
关注字段:
| 字段 | 含义 |
|---|---|
status |
0 = 失败, 1 = 成功 |
gasUsed |
实际消耗的 gas |
logs |
空数组 [] = 交易 revert,无事件发出 |
to |
目标合约地址 |
Step 2: 获取交易详情 — 拿到 gas limit 和 input
cast tx <tx_hash> --rpc-url $RPC_URL
关注字段:
| 字段 | 含义 |
|---|---|
gas |
发送方设置的 gas limit |
input |
调用的 calldata(函数选择器 + 参数编码) |
from / to |
发送方和目标合约 |
value |
发送的原生代币数量 |
Step 3: 判断失败类型 — gasUsed vs gas limit
| 现象 | 判断 | 解决方向 |
|---|---|---|
| gasUsed / gas ≈ 100%(如 999,472 / 1,000,000) | Out of Gas (OOG) | 提高 gas limit 或用 eth_estimateGas |
| gasUsed 远低于 gas limit(如 50,000 / 1,000,000) | Revert | 需获取 revert reason,见 Step 6 |
| gasUsed 正常但 status=0 | 内部调用失败 | 检查余额、授权、内部 call 返回值 |
| 交易根本没上链 | Nonce/Gas Price 问题 | 检查 pending 队列 |
Step 4: 解码函数选择器 — 确定调用了什么函数
# 从 input 的前 4 字节查函数签名
cast 4byte 0xb51a038a
# 输出示例: unstake(uint256,address[],uint256[])
Step 5: 解码完整 calldata — 还原调用参数
# 用 Step 4 得到的函数签名解码
cast calldata-decode "unstake(uint256,address[],uint256[])" <完整input_data>
解码后的参数可用于:
- 分析入参是否有误
- 直接用于重试交易
Step 6: 获取 Revert Reason(非 OOG 场景)
# 方法 A: cast call 模拟(指定失败区块号,用交易所在区块)
cast call <to> <input_data> \
--from <from> \
--block-number <block_number> \
--rpc-url $RPC_URL
# 方法 B: cast run 重放交易(需要 archive 节点)
cast run <tx_hash> --rpc-url <archive_rpc_url>
# 方法 C: 在线工具(备用)
# 使用 Tenderly 或 Blocksec Phalcon 等交易分析平台
Step 7: 查询链上状态 — 确认交易失败后数据已回滚
# 查询 public 变量/映射
cast call <contract> "orderLocations(uint256)(address,uint256,bool)" <id> --rpc-url $RPC_URL
# 查询 struct 字段(按 ABI 顺序指定返回类型)
cast call <contract> "userStakeRecord(address,uint256)(uint40,uint160,bool,uint8,uint256)" <user> <index> --rpc-url $RPC_URL
失败交易的状态变更会完全回滚,需确认数据仍在原始状态。
Step 8: 对比成功 vs 失败交易 — 找差异
将成功和失败的交易放在一起对比:
| 对比维度 | 说明 |
|---|---|
| gas 消耗 | 判断是否 OOG |
| 调用参数 | 判断是否入参问题 |
| 目标地址 | 判断是否调错合约 |
| 区块时间 | 判断是否有时间锁等限制 |
| 合约状态 | 判断是否前置条件不满足 |
Step 9: 重试交易
source .env
# 不指定 gas limit(让节点自动估算,推荐)
cast send <contract> "functionName(uint256,address[],uint256[])" <arg1> "[<addr1>,<addr2>]" "[<amt1>,<amt2>]" \
--account <KEYSTORE_NAME> \
--rpc-url $RPC_URL \
--legacy
# 指定较高 gas limit(适用于已知消耗范围的场景)
cast send <contract> "functionName(uint256)" <arg1> \
--account <KEYSTORE_NAME> \
--rpc-url $RPC_URL \
--gas-limit 2000000 \
--legacy
安全注意事项
| 规则 | 说明 |
|---|---|
| 私钥管理 | 使用 Foundry Keystore (--account) 管理私钥,禁止在命令中明文传入 |
| 模拟优先 | 真实发送前先用 cast call 模拟,确认不会 revert |
| 逐笔发送 | 批量重试时先发一笔验证,成功后再发剩余 |
| 状态确认 | 发送后用 cast receipt 确认 status=1,再用 cast call 确认链上状态已变更 |
完整示例流程
source .env
# 1. 看回执
cast receipt 0x4ca1...414f --rpc-url $RPC_URL
# 2. 看交易详情
cast tx 0x4ca1...414f --rpc-url $RPC_URL
# 3. 发现 gas=1000000, gasUsed=999472, status=0 → OOG
# 4. 解码函数选择器
cast 4byte 0xb51a038a
# → unstake(uint256,address[],uint256[])
# 5. 解码完整参数
cast calldata-decode "unstake(uint256,address[],uint256[])" 0xb51a038a...
# 6. 模拟确认能通过
cast call <contract> "unstake(uint256,address[],uint256[])" 35 "[addr1,addr2]" "[amt1,amt2]" \
--from <from> --rpc-url $RPC_URL
# 7. 查链上状态确认订单仍未处理
cast call <contract> "orderLocations(uint256)(address,uint256,bool)" 35 --rpc-url $RPC_URL
# 8. 确认是 OOG → 不限 gas 重试
cast send <contract> "unstake(uint256,address[],uint256[])" 35 "[addr1,addr2]" "[amt1,amt2]" \
--account <KEYSTORE_NAME> --rpc-url $RPC_URL --legacy
# 9. 确认成功
cast receipt <new_tx_hash> --rpc-url $RPC_URL