본문으로 건너뛰기
cccskills
무료GitHub에 공개

abi-codegen

Convert JSON ABI files to TypeScript const exports with proper typing. Use when working with smart contract ABIs, converting JSON to TypeScript, generating typed contract interfaces, or adding new contract ABIs to the SDK.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

JSON to TypeScript ABI Converter

Purpose

Automates the conversion of JSON ABI files to TypeScript files with properly typed const exports, ensuring type safety and consistency across the SDK.

When to Use

  • Adding new contract ABIs to the SDK
  • Updating existing ABI files after contract changes
  • Batch converting multiple ABI files
  • Ensuring ABI TypeScript files match their JSON sources

How It Works

The skill provides a conversion script that:

  1. Reads JSON ABI file(s) from src/evm/abi/
  2. Generates TypeScript files in src/evm/releases/ with:
    • Named export using camelCase convention
    • as const assertion for full type inference
    • Preserved JSON structure
  3. Automatically runs Biome formatting on generated files

Usage

Single File Conversion

bun .claude/skills/abi-codegen/scripts/codegen.ts src/evm/abi/lockup/v3.0/SablierLockup.json

Multiple Files (Glob Pattern)

bun .claude/skills/abi-codegen/scripts/codegen.ts "src/evm/abi/lockup/v3.0/*.json"

All ABIs in Directory

bun .claude/skills/abi-codegen/scripts/codegen.ts "src/evm/abi/**/*.json"

File Path Conventions

Input Path Pattern

src/evm/abi/{protocol}/{version}/{ContractName}.json

Output Path Pattern

src/evm/releases/{protocol}/{version}/abi/{ContractName}.ts

Naming Convention

  • JSON file: SablierLockup.json
  • TS export: sablierLockupAbi
  • Pattern: PascalCase filename → camelCase + "Abi" suffix

Examples

Example 1: Convert Lockup ABI

Input: src/evm/abi/lockup/v3.0/SablierLockup.json

[
  {
    "inputs": [
      { "internalType": "address", "name": "to", "type": "address" },
      { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
    ],
    "name": "approve",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Command:

bun .claude/skills/abi-codegen/scripts/codegen.ts src/evm/abi/lockup/v3.0/SablierLockup.json

Output: src/evm/releases/lockup/v3.0/abi/SablierLockup.ts

export const sablierLockupAbi = [
  {
    inputs: [
      { internalType: "address", name: "to", type: "address" },
      { internalType: "uint256", name: "tokenId", type: "uint256" },
    ],
    name: "approve",
    outputs: [],
    stateMutability: "nonpayable",
    type: "function",
  },
] as const;

Example 2: Batch Convert All v3.0 Lockup ABIs

bun .claude/skills/abi-codegen/scripts/codegen.ts "src/evm/abi/lockup/v3.0/*.json"

Output:

✓ Converted: SablierLockup.json → SablierLockup.ts
✓ Converted: SablierLockupDynamic.json → SablierLockupDynamic.ts
✓ Converted: SablierLockupLinear.json → SablierLockupLinear.ts
✓ Converted: SablierLockupTranched.json → SablierLockupTranched.ts

Running Biome formatter...
✓ Formatted 4 files

Done! Converted 4 ABI files.

Script Details

Input Processing

  • Accepts absolute or relative file paths
  • Supports glob patterns via Bun's Glob API
  • Validates JSON structure before conversion
  • Handles missing or malformed files gracefully

Output Generation

  • Creates necessary directories automatically
  • Preserves JSON structure exactly (no data loss)
  • Applies consistent naming convention
  • Adds as const for maximum type inference

Post-Processing

  • Runs just biome-write on all generated TypeScript files
  • Ensures consistent formatting with project standards
  • Reports any formatting errors

Error Handling

The script handles common errors:

  • File not found: Clear error message with file path
  • Invalid JSON: Shows parsing error with line/column
  • Write permission: Reports directory/file permission issues
  • Biome errors: Displays formatting failures (non-fatal)

Troubleshooting

Script Not Found

# Ensure you're in the project root
pwd  # Should show .../sablier/sdk

# Verify script exists
ls .claude/skills/abi-codegen/scripts/codegen.ts

Invalid JSON

# Validate JSON before converting
jq . src/evm/abi/lockup/v3.0/SablierLockup.json

TypeScript Errors After Conversion

# Run type check to verify
just tsc-check

# If errors occur, check:
# 1. Is the JSON structure valid for an ABI?
# 2. Are all required fields present?
# 3. Run Biome again: just biome-write

Glob Pattern Not Working

# Use quotes around glob patterns
bun .claude/skills/abi-codegen/scripts/codegen.ts "src/evm/abi/**/*.json"
#                                                 ^                    ^
#                                                 Quotes are required

Integration with Workflow

After Adding New ABIs

  1. Place JSON ABI in src/evm/abi/{protocol}/{version}/
  2. Run conversion script
  3. Verify output in src/evm/releases/{protocol}/{version}/abi/
  4. Run just tsc-check to verify types
  5. Export from appropriate index file
  6. Run just test to ensure no regressions

Before Committing ABI Changes

# Convert all modified ABIs
bun .claude/skills/abi-codegen/scripts/codegen.ts "src/evm/abi/**/*.json"

# Verify TypeScript
just tsc-check

# Run tests
just test

# Commit both JSON and generated TS files
git add src/evm/abi/ src/evm/releases/
git commit -m "feat: update ABIs for {protocol} {version}"

Technical Notes

Why as const?

The as const assertion provides:

  • Literal types: String values become literal types (e.g., "function" not string)
  • Readonly arrays: Prevents accidental mutations
  • Better inference: Viem uses literal types for better type checking
  • Autocomplete: IDEs provide better suggestions

Why Separate JSON and TS?

  • Source of truth: JSON files are copied from Foundry artifacts
  • Version control: Easy to see diffs in JSON changes
  • Type safety: TypeScript provides compile-time checks
  • Build optimization: TypeScript files can be tree-shaken

Performance

  • Typical conversion: <100ms per file
  • Batch processing: ~500ms for 10 files
  • Biome formatting: ~1-2s for all files
  • Total overhead: Minimal, suitable for pre-commit hooks

Related Files

  • Script: .claude/skills/abi-codegen/scripts/codegen.ts
  • Source ABIs: src/evm/abi/{protocol}/{version}/*.json
  • Output ABIs: src/evm/releases/{protocol}/{version}/abi/*.ts
  • Build config: tsconfig.build.json (includes ABI copy step)

Future Enhancements

Potential improvements:

  • Watch mode for automatic conversion on JSON changes
  • Validation against official ABI schema
  • Diff detection to only convert changed files
  • Integration with Foundry broadcast parsing
  • Automatic export statement generation in index files

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Master backend architectures, REST API design, microservices, and server-side development across multiple languages. Use this as a central index to access specialized sub-skills.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

在每次回复中使用固定前缀并列出本次实际参考的指令/文件,便于校验是否遵循上下文与规则。

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

Automate 21risk tasks via Rube MCP (Composio). Always search tools first for current schemas.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

Automate 2chat tasks via Rube MCP (Composio). Always search tools first for current schemas.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

Arquitecto de Soluciones Principal y Consultor Tecnológico de Andru.ia. Diagnostica y traza la hoja de ruta óptima para proyectos de IA en español.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

[00] META. Orchestrate skills into dynamic chains for complex tasks. Analyzes the task, discovers available skills, builds an optimal chain, explains why each skill is needed, and executes step-by-step with user confirmation. Use for any complex task requiring multiple thinking/research/analysis steps. Triggers on "plan this", "how to approach", "what's the strategy", "build a plan", or any multi-step problem requiring skill orchestration.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

MikeCheng1208/BattleTree22026년 7월 22일 업데이트

MikeCheng1208의 스킬 모두 보기

이 스킬의 문제 신고