examples/

directory
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: MIT

README

Examples

This directory contains example programs demonstrating how to use the multicall library.

Running Examples

Each example can be run from its directory. You can optionally set the ETH_RPC_URL environment variable to use a custom RPC endpoint.

cd builtin
go run main.go

# Or with custom RPC
ETH_RPC_URL=https://your-rpc-url.com go run main.go

Examples

builtin

Demonstrates using Multicall3 built-in methods directly with package-level pack/unpack functions.

  • Query blockchain state (block number, chain ID, base fee)
  • Query ETH balances for multiple addresses
  • Uses convenience functions like TryPackGetBlockNumber, UnpackGetBlockNumber
cd builtin
go run main.go
result-based

Demonstrates the Result-Based pattern: Add calls and get a Result reference, then read results after Execute() completes.

cd result-based
go run main.go
callback-based

Demonstrates the Callback-Based pattern: Add calls with callback functions that automatically receive results during Execute().

cd callback-based
go run main.go

Expected Output

builtin
=== Blockchain State ===
Block Number: 12345678
Chain ID:     1
Base Fee:     30000000000 wei
Timestamp:    1234567890
Last Hash:    0xabcd...

=== ETH Balances ===
Vitalik:  123.456789 ETH
Uniswap:  987.654321 ETH
result-based / callback-based
USDT: Tether USD (USDT)
USDC: USD Coin (USDC)
WETH: Wrapped Ether (WETH) - 18 decimals

Directories

Path Synopsis
Package main demonstrates using Multicall3 built-in methods These methods are available as package-level functions for convenience.
Package main demonstrates using Multicall3 built-in methods These methods are available as package-level functions for convenience.
Package main demonstrates Pattern 2: Callback-Based usage of multicall Add calls with a callback function that automatically receives results during Execute().
Package main demonstrates Pattern 2: Callback-Based usage of multicall Add calls with a callback function that automatically receives results during Execute().
Package main demonstrates Pattern 1: Result-Based usage of multicall Add calls and get a Result reference.
Package main demonstrates Pattern 1: Result-Based usage of multicall Add calls and get a Result reference.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL