360 Secure SkillHub
360 安全技能中心

fetch-evm-logs

在目标目录生成 Node.js + TypeScript 项目并安装依赖,要求用户显式提供合约 ABI 及地址、chainId、RPC、区块范围、事件名等配置,随后运行 s1 拉取 eth_getLogs 输出 logs.txt、s2 按 ABI 解析为 logs.json。范围仅拉取与解析,不含 s3 统计聚合。

分类:数据
lkkchen
lkkchen
热度 12.58
最近更新 2026-07-20 11:10:49

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add lkkchen/fetch-evm-logs
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
fetch-evm-logs
description
Scaffold and run a Node.js EVM event log pipeline (eth_getLogs pull + ABI parse). Use when the user wants to initialize fetch_evm_logs from scratch, fetch on-chain logs, or adapt contract/event config on a new machine without an existing repo. Requires explicitly asking the user to provide the contract ABI before configuration. Scope is pull + parse only (s1/s2); do not run stats or s3 in this skill.

Fetch EVM Logs

Self-contained skill for fetching EVM event logs only: scaffold → ask user for ABI → configure → run s1/s2.

init-project.sh  →  user provides ABI  →  edit contract.ts  →  pnpm s1  →  pnpm s2

Bundled templates live in this skill's templates/ directory (no external repo required).

Out of scope: aggregation, claim stats, CSV metrics, or pnpm s3. For those, use the separate evm-log-stats skill.

Step 0 — Initialize project

When the user asks to fetch logs and no project exists yet, scaffold first:

bash ~/.cursor/skills/fetch-evm-logs/scripts/init-project.sh [target_dir]

Default target: ./fetch_evm_logs. Creates full Node.js + TypeScript project, runs pnpm install.

Agent workflow:

  1. Ask or infer target directory (default fetch_evm_logs in workspace).
  2. Run init-project.sh from the skill directory.
  3. Proceed to configuration below.

Do not ask the user to clone a repo — this skill ships the template.

Step 1 — Obtain contract ABI from user

Mandatory. Before writing src/abi/ or editing contract.ts, explicitly ask the user to provide the contract ABI.

Ask clearly, for example:

请提供目标合约的 ABI(完整合约 ABI JSON,或至少包含目标 event 的 fragment)。可从 Etherscan「Contract → Code → Contract ABI」复制,或直接粘贴 JSON。

Do not:

  • Use the bundled placeholder ABI as the real ABI
  • Guess or fabricate an ABI from the event name alone
  • Fetch ABI from a block explorer unless the user explicitly asks you to

Wait for the user to supply ABI (paste in chat, or point to a local file). Collect contract address and chainId first (Step 2), then write ABI to:

src/abi/abi_{address}_{chainId}.json

Example: src/abi/abi_0x4ccdb547cdfd4d3b929d4556ddf9f5ed9d861aad_41443.json

  • address is lowercase
  • No manual import in contract.ts — ABI is loaded automatically from this path

Acceptable formats:

  • Full contract ABI JSON array
  • Minimal event fragment array containing the target event

If the user also provides eventName, use it; otherwise infer the event name from the ABI and confirm with the user before running s1.

Step 2 — Gather other contract info

Ask or infer the remaining fields (can be collected together with Step 1):

Item Example
Contract address 0x4CcDb...
RPC URL https://...
Block range startBlock, endBlock or latest
Event name AirdropClaimed (must exist in user-provided ABI)
Token decimals 18 (optional)
chainId 41443

Step 3 — Configure

ABI file: src/abi/abi_{address}_{chainId}.json

Write the user-provided ABI using the naming rule above. contract.ts loads it by address + chainId — no import statement needed.

src/contract.ts

export const Distributors = {
  contracts: {
    MyContract: {
      address: '0x...',
      startBlock: 735573,
      endBlock: 'latest',
      rpc: 'https://...',
      chainId: 41443,
      eventName: 'AirdropClaimed',  // must match ABI event name
      tokenDecimals: 18,
    },
  },
};
  • parseLog and topic hash are auto-built from ABI (utils/parse.log.ts).
  • Parsed data keys match ABI param names (account, root, amount, …).

Step 4 — Run

cd <target_dir>
pnpm s1    # pull → output/{address}_{chainId}/logs.txt
pnpm s2    # parse → output/{address}_{chainId}/logs.json
pnpm typecheck

Stop after s2. Do not run pnpm s3 or edit stats.config.ts under this skill.

Project layout (after scaffold)

fetch_evm_logs/
├── package.json          # s1, s2 scripts (s3 may exist in template; ignore here)
├── tsconfig.json
├── src/
│   ├── contract.ts       # ← customize
│   ├── abi/abi_{address}_{chainId}.json  # ← user-provided ABI
│   ├── s1.pull.contract.logs.ts
│   ├── s2.prase.logs.ts
│   └── utils/
└── output/
    └── {address}_{chainId}/
        ├── logs.txt
        └── logs.json

Do not edit s1, s2, utils/parse.log.ts, utils/utils.pull.log.ts unless switching to block-explorer API.

Parsed log shape

{ txHash: string; blockNumber: number; data: Record<string, string | boolean> }

Checklist

- [ ] init-project.sh completed
- [ ] User provided ABI (not placeholder)
- [ ] ABI written to src/abi/abi_{address}_{chainId}.json
- [ ] contract.ts configured
- [ ] pnpm s1 → verify log count
- [ ] pnpm s2 → spot-check data.* fields

Pitfalls

  • Wrong eventName → zero logs
  • RPC range too large → reduce pageSize in s1 (default 1000)
  • Wrong tokenDecimals → amount scale errors
  • ABI filename must match abi_{address}_{chainId}.json (lowercase address)
  • Downstream field names must use ABI names (account, not address)

Additional Resources