← 返回 Skills 市场
old-greggyboy

Abi Toolchain

作者 old-greggyboy · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
172
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install abi-toolchain
功能描述
ABI lifecycle management for smart contract projects. Use when your frontend is out of sync with contract changes, when you need to set up ABI generation in...
使用说明 (SKILL.md)

ABI Toolchain

Treat your ABI like any other versioned artifact. Most frontend-contract sync bugs are ABI lifecycle problems in disguise.

Scripts

Ready-to-use tools in scripts/:

Script Purpose
sync-abi.sh Sync compiled ABIs from Foundry/Hardhat artifacts to frontend
abi-diff.js Compare two ABI files: find added/removed/changed, flag breaking changes

sync-abi.sh

# Set which contracts to sync: create .abi-sync in your project root
echo "MyToken" >> .abi-sync
echo "MyVault:Vault" >> .abi-sync   # writes as Vault.json

# Run from your project root
ABI_SOURCE=out ABI_DEST=frontend/src/abis bash path/to/sync-abi.sh

# Or use defaults (Foundry: out/ → frontend/src/abis/)
bash scripts/sync-abi.sh

Handles both Foundry (out/Foo.sol/Foo.json) and Hardhat (artifacts/contracts/) artifacts. Uses jq if available, falls back to Python.

abi-diff.js

node scripts/abi-diff.js old/MyToken.json new/MyToken.json
# → { added: [], removed: [], changed: [], breaking: false, summary: "0 added, 0 removed, 1 changed" }

# Exit code 1 if breaking changes (useful in CI):
node scripts/abi-diff.js prev.json current.json || echo "BREAKING CHANGE"

Accepts raw ABI arrays or Foundry/Hardhat artifacts (auto-detected).

ABI Types Reference

See references/abi-formats.md for complete coverage of ABI entry types, function selectors, event topics, Foundry artifact structure, and common gotchas (tuples, uint vs uint256, as const).

The Core Problem

When a contract changes:

  1. New ABI gets compiled by Foundry/Hardhat
  2. Frontend still imports the old ABI from a file that wasn't updated
  3. Calls either fail silently or revert on-chain

The fix isn't careful manual updating — it's making the pipeline impossible to get wrong.

Pattern 1: Foundry → TypeScript Auto-Sync

After every forge build, auto-export ABIs to your frontend:

# scripts/sync-abi.sh
#!/bin/bash
set -e
CONTRACTS=("MyToken" "MyVault" "MyFactory")
SRC="out"           # Foundry output dir
DEST="frontend/src/abis"

mkdir -p $DEST

for contract in "${CONTRACTS[@]}"; do
  jq '.abi' "$SRC/$contract.sol/$contract.json" > "$DEST/$contract.json"
  echo "✅ Synced $contract ABI"
done

Add to foundry.toml as a post-build hook or wire into package.json:

{
  "scripts": {
    "build:contracts": "forge build && bash scripts/sync-abi.sh",
    "dev": "npm run build:contracts && next dev"
  }
}

Pattern 2: Typed ABIs with Viem (no codegen)

Viem's as const trick gives you full TypeScript types directly from your ABI JSON:

// abis/MyToken.ts — export from your synced JSON
export const myTokenAbi = [
  {
    name: 'transfer',
    type: 'function',
    stateMutability: 'nonpayable',
    inputs: [{ name: 'to', type: 'address' }, { name: 'amount', type: 'uint256' }],
    outputs: [{ name: '', type: 'bool' }],
  },
  // ...
] as const   // ← critical: makes TypeScript infer exact types

// Now readContract/writeContract will type-check function names and args
const result = await client.readContract({
  abi: myTokenAbi,
  functionName: 'transfer',  // ← autocompletes, typos caught at compile time
  args: ['0x...', 100n],     // ← arg types inferred
})

Pattern 3: Wagmi CLI Code Generation

For large projects, @wagmi/cli generates fully typed React hooks from your ABIs:

npm install --save-dev @wagmi/cli
// wagmi.config.ts
import { defineConfig } from '@wagmi/cli'
import { foundry, react } from '@wagmi/cli/plugins'

export default defineConfig({
  out: 'src/generated.ts',
  plugins: [
    foundry({ project: '../contracts' }),  // reads Foundry artifacts directly
    react(),                                // generates useReadMyToken, useWriteMyToken, etc.
  ],
})
npx wagmi generate   # regenerate on every contract change

Add to CI: npx wagmi generate && git diff --exit-code src/generated.ts — fails if ABI was changed but not regenerated.

Pattern 4: Proxy Contract ABIs

Proxy contracts (UUPS, Transparent) have two ABIs:

  1. Proxy ABI — just upgradeTo, upgradeToAndCall, admin functions
  2. Implementation ABI — your actual business logic

Always use the implementation ABI for user-facing calls, pointed at the proxy address:

// WRONG: using proxy ABI loses all your functions
const client = getContract({ address: proxyAddr, abi: proxyAbi })

// RIGHT: implementation ABI + proxy address
const client = getContract({ address: proxyAddr, abi: myContractV2Abi })

For Hardhat upgrades, the generated .json artifacts include the merged ABI automatically. For Foundry, merge manually:

# Merge proxy + implementation ABIs
jq -s '.[0].abi + .[1].abi | unique_by(.name)' \
  out/ERC1967Proxy.sol/ERC1967Proxy.json \
  out/MyContractV2.sol/MyContractV2.json \
  > frontend/src/abis/MyContractProxy.json

Pattern 5: CI/CD Enforcement

Block merges where ABI changed but frontend wasn't updated:

# .github/workflows/abi-check.yml
- name: Check ABI sync
  run: |
    forge build
    bash scripts/sync-abi.sh
    git diff --exit-code frontend/src/abis/
    # Fails if any ABI file was changed without committing the update

Common Failure Modes

Symptom Cause Fix
function not found on-chain Calling old function name that was renamed Re-sync ABI, check function selector
TypeScript accepts wrong arg type as const missing on ABI Add as const to ABI definition
Proxy call reverts Using proxy ABI instead of implementation ABI Always use implementation ABI at proxy address
Works in dev, fails on mainnet ABI from local build ≠ deployed contract Pin ABI to verified deployment, not latest build
Wagmi hook types wrong Generated file not up to date Re-run npx wagmi generate

References

安全使用建议
This skill appears coherent and implements ABI sync/diff features as described. Before running it in a real repo: 1) Inspect scripts locally (they are included) to verify ABI_DEST and CONTRACTS are correct; 2) Back up or run in a feature branch — sync-abi.sh will overwrite files under ABI_DEST; 3) Check your .abi-sync lines (or ABI_CONTRACTS) for accidental path traversal or unexpected output names; 4) Ensure your CI runner has jq/node/python as needed; 5) If you plan to run this in CI, add a dry-run or commit checks so accidental overwrites are visible. If any part of your workflow requires stricter safety (e.g., preventing writes outside a subdirectory), add validation/sanitization around output names before using the script.
功能分析
Type: OpenClaw Skill Name: abi-toolchain Version: 1.0.1 The bundle provides legitimate developer utilities for managing Smart Contract ABIs, including a bash script (sync-abi.sh) for syncing artifacts and a Node.js script (abi-diff.js) for detecting breaking changes. The documentation in SKILL.md and references/abi-formats.md is well-structured and aligned with the stated purpose of ABI lifecycle management, with no evidence of malicious intent, data exfiltration, or harmful prompt injection.
能力评估
Purpose & Capability
Name/description describe ABI lifecycle tooling and the included scripts (sync-abi.sh and abi-diff.js) implement exactly that functionality (extract ABIs from Foundry/Hardhat artifacts, write to frontend, and compare ABIs). Required resources and behavior are proportionate to the purpose.
Instruction Scope
SKILL.md and the scripts operate only on local build artifacts and repo paths and describe CI usage. They read .abi-sync or ABI_CONTRACTS, locate JSON artifacts under ABI_SOURCE, extract .abi and write JSON files to ABI_DEST. This is expected, but the scripts will overwrite files in the repo and accept names from .abi-sync/ABI_CONTRACTS without sanitization (e.g., a crafted entry like '../foo' could write outside the intended directory). Review .abi-sync entries and test in a branch before running.
Install Mechanism
No install spec (instruction-only with shipped scripts). No downloads or external installers; the scripts rely on common local tools (jq, python/node) with fallbacks, which is low-risk.
Credentials
No credentials or secret environment variables requested. The scripts accept optional environment variables (ABI_SOURCE, ABI_DEST, ABI_CONTRACTS) which are directly related to their function.
Persistence & Privilege
Skill is not marked always:true and does not request permanent agent-wide privileges. It does write files into the project workspace (expected for its purpose) but does not modify other skills or system-wide agent settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install abi-toolchain
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /abi-toolchain 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
No user-visible changes in this release. - Version number bumped to 1.0.1 with no modifications to files or documentation.
v1.0.0
- Initial release of abi-toolchain: tools and patterns for ABI lifecycle management in smart contract projects. - Includes scripts to sync ABIs between contract artifacts and frontend (`sync-abi.sh`) and to compare ABI files (`abi-diff.js`). - Documentation covers best practices for ABI syncing, typed ABIs with Viem, Wagmi CLI code generation, proxy contract ABI handling, and CI/CD enforcement. - Provides references and troubleshooting for common ABI-related integration issues.
元数据
Slug abi-toolchain
版本 1.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

Abi Toolchain 是什么?

ABI lifecycle management for smart contract projects. Use when your frontend is out of sync with contract changes, when you need to set up ABI generation in... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 172 次。

如何安装 Abi Toolchain?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install abi-toolchain」即可一键安装,无需额外配置。

Abi Toolchain 是免费的吗?

是的,Abi Toolchain 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Abi Toolchain 支持哪些平台?

Abi Toolchain 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Abi Toolchain?

由 old-greggyboy(@old-greggyboy)开发并维护,当前版本 v1.0.1。

💬 留言讨论