This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
polygon-cli is a Swiss Army knife of blockchain tools for building, testing, and running blockchain applications. It's a collection of utilities primarily focused on Polygon/Ethereum ecosystems.
The project follows a command-based architecture using Cobra framework:
- Main Entry:
main.gosimply callscmd.Execute() - Command Structure: Each command is organized in its own package under
cmd/(e.g.,cmd/loadtest/,cmd/monitor/) - Bindings: Go bindings for smart contracts are in
bindings/(generated from Solidity contracts incontracts/) - Utilities: Common utilities are in
util/package
Key architectural patterns:
- Commands are self-contained with their own usage documentation (
.mdfiles) - Heavy use of code generation for documentation, protobuf, contract bindings, and RPC types
- Docker-based generation workflows to ensure consistency
# Build the binary
make build
# Install to ~/go/bin/
make install
# Cross-compile for different platforms
make cross # With CGO
make simplecross # Without CGO# Run all tests with coverage
make test
# Run specific test
go test -v ./cmd/loadtest/...
# Run load test against local node
make geth # Start local geth node
make geth-loadtest # Fund account and run load test# Run all linters (includes tidy, vet, golangci-lint)
make lint
# Individual linter commands
make tidy # Clean up go.mod
make fmt # Format code
make vet # Run go vet and shadow
make golangci-lint # Run golangci-lint# Generate everything (docs, proto, bindings, etc.)
make gen
# Individual generation commands
make gen-doc # Generate CLI documentation
make gen-proto # Generate protobuf stubs
make gen-go-bindings # Generate contract bindings
make gen-load-test-modes # Generate loadtest mode strings
make gen-json-rpc-types # Generate JSON RPC types# Work with smart contracts
cd contracts/
make build # Build contracts with Foundry
make gen-go-bindings # Generate Go bindingsWhen adding a new command:
- Create a new package under
cmd/your-command/ - Add the command to
cmd/root.goin theNewPolycliCommand()function - Create a usage documentation file (e.g.,
yourCommandUsage.md) - Run
make gen-docto update the main documentation - If adding a new loadtest mode, run
make gen-load-test-modesafter using stringer
The CI pipeline (/.github/workflows/ci.yml) runs:
- Linting (golangci-lint, shadow)
- Tests
- Generation checks (ensures all generated files are up-to-date)
- Load tests against both geth and anvil
Always run make gen before committing if you've changed anything that affects code generation.
- Go 1.23+ required
- Foundry (for smart contract compilation)
- Docker (for generation tasks)
- Additional tools: jq, bc, protoc (for development)
The tool supports configuration via:
- CLI flags (highest priority)
- Environment variables
- Config file (
~/.polygon-cli.yaml) - Viper is used for configuration management
- Use zerolog for structured, performant logging throughout the project
- Use conventional commit messages
- Use
make buildto build polycli