home / skills / melonask / evm-balance-skills / evm-balance-skills

evm-balance-skills skill

/SKILL.md

This skill helps you fetch EVM balances across chains using Multicall3 via a CLI and SDK for fast, reliable currency insights.

npx playbooks add skill melonask/evm-balance-skills --skill evm-balance-skills

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
3.5 KB
---
name: evm-balance
description: Comprehensive guide for the EVM Balance project, including CLI usage, SDK integration, and development workflow. Use when working with EVM balance fetching, configuring the CLI, or integrating the SDK.
---

# EVM Balance Skill

## Overview

The `evm-balance` project is a high-performance library and CLI for fetching EVM balances across multiple chains using Multicall3. It supports native and ERC20 token balances, address generation (XPUB, CREATE2), and batch processing.

**Key Components:**
- **SDK** (`@evm-balance/sdk`): Core library for fetching balances.
- **CLI** (`@evm-balance/cli`): Command-line interface for easy interaction.
- **Contracts**: Solidity contracts for Multicall3 interactions.

## Project Structure

```
evm-balance/
├── packages/
│   ├── sdk/              # Core library
│   │   ├── src/
│   │   │   ├── index.ts     # Main exports
│   │   │   ├── types.ts     # TypeScript interfaces
│   │   │   ├── balance.ts   # Balance fetching logic
│   │   │   ├── multicall.ts # Multicall3 encoding/decoding
│   │   │   ├── chains.ts    # Chain utilities
│   │   │   └── utils.ts     # Range parsing, formatting
│   │   └── package.json
│   └── cli/              # CLI tool
│       ├── src/
│       │   └── index.ts     # CLI implementation
│       └── package.json
├── src/                  # Solidity contracts
│   └── Multicall3.sol
├── script/               # Deployment scripts
│   └── DeployTest.s.sol
└── package.json          # Workspace root
```

## CLI Usage

The CLI provides a powerful interface for fetching balances.

### Quick Start

```bash
# Query multiple chains
evm-balance 0-100 --chain mainnet,optimism,arbitrum --xpub $XPUB

# Query specific tokens
evm-balance 0-100 -c mainnet -t 0xA0b86991...USDC,0xdAC17F9...USDT -X $XPUB

# Filter by minimum balance
evm-balance 0-1000 -c mainnet -t 0xUSDT,0xUSDC --min 0.1

# Output as JSON
evm-balance 0-100 -c mainnet -f json -o balances.json
```

### Common Options

- `-c, --chains`: Comma-separated chain names or IDs (e.g., `mainnet,optimism`).
- `-t, --tokens`: Comma-separated ERC20 token addresses.
- `-m, --min`: Minimum balance filter.
- `-f, --format`: Output format (`table`, `json`, `csv`).
- `-X, --xpub`: Extended public key for BIP-44 address generation.
- `--mode`: Address generation mode (`xpub` or `factory`).

## SDK Usage

The SDK allows programmatically fetching balances.

### Basic Example

```typescript
import { createBalanceFetcher, parseRange, mainnet } from "@evm-balance/sdk";

const fetcher = createBalanceFetcher({ chain: mainnet });

const results = await fetcher.fetchBalances({
  config: { chain: mainnet },
  mode: { type: "xpub", xpub: process.env.XPUB! },
  indices: parseRange("0-100"),
  options: {
    tokens: ["0xA0b86991..."], // USDC
    includeNative: true,
  },
});
```

**For detailed API documentation, see [sdk_api.md](references/sdk_api.md).**

## Development Workflow

### Prerequisites
- `bun`
- `foundry` (forge, anvil)

### Commands

```bash
# Install dependencies
bun install

# Build all packages
bun run build

# Run tests
bun run test

# Run Solidity tests (requires Anvil)
bun run test:sol

# Type check
bun run typecheck

# Format code
bun run fmt
```

### Testing with Anvil

```bash
# 1. Start Anvil
anvil

# 2. Deploy test contracts
forge script script/DeployTest.s.sol:DeployTest --rpc-url http://127.0.0.1:8545 --broadcast

# 3. Run tests
bun run test
```

Overview

This skill is a concise, hands-on guide for the EVM Balance project, covering the SDK, CLI, and development workflow. It explains how to fetch native and ERC20 balances across multiple EVM chains using Multicall3, generate addresses, and run the local test environment. Use it to get started quickly or integrate high-performance balance fetching into your tools.

How this skill works

The project exposes a core SDK for programmatic balance queries and a CLI for interactive or scriptable use. Both use Multicall3 encoding/decoding to batch requests across chains, support native and ERC20 token balances, and offer address generation modes (XPUB/BIP-44 and CREATE2/factory). The SDK accepts ranges of indices, token lists, and chain configs to return compact balance results.

When to use it

  • Integrating fast, batched balance checks into a backend or analytics pipeline.
  • Exploring balances across many addresses generated from an XPUB or factory contract.
  • Running ad-hoc multi-chain balance audits from your terminal.
  • Filtering large address sets by minimum balance before further processing.
  • Developing or testing Multicall3-based logic locally with Solidity contracts.

Best practices

  • Use Multicall3 and the SDK’s batch options to minimize RPC calls and reduce cost.
  • Prefer index ranges and XPUB mode for deterministic address generation at scale.
  • Filter by minimum balance client-side to avoid storing irrelevant results.
  • Choose output format (json/csv/table) to match downstream tooling; use json for programmatic workflows.
  • Run local tests with Anvil and deploy test contracts via forge for reproducible development.

Example use cases

  • Generate 0–100 addresses from an XPUB and fetch native + USDC balances across mainnet and optimisim.
  • Run a nightly job that queries balances for many addresses and writes JSON to storage for analytics.
  • Quick CLI check to list addresses with >0.1 token balance before initiating token sweeps.
  • Integrate the SDK into a dashboard backend to show aggregated token holdings per address range.
  • Develop and validate Multicall3 contract interactions locally using Anvil and Forge deployment.

FAQ

Which address generation modes are supported?

XPUB (BIP-44 deterministic addresses) and factory/CREATE2-style generation are supported via the CLI and SDK.

How do I run tests locally?

Install bun and Foundry, start Anvil, deploy test contracts with forge script, then run bun test as documented in the workflow.