Comprehensive guide for the EVM Balance project, including CLI usage, SDK integration, and development workflow...
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:
@evm-balance/sdk): Core library for fetching balances.@evm-balance/cli): Command-line interface for easy interaction.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
The CLI provides a powerful interface for fetching balances.
# 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
-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).The SDK allows programmatically fetching balances.
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.
bunfoundry (forge, anvil)# 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
# 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