This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Moonbeam is an Ethereum-compatible parachain built with Polkadot-SDK. It's a Rust-based blockchain project that enables Ethereum-style smart contracts on Polkadot/Kusama networks.
# Build the Moonbeam node (optimized release build)
cargo build --release
# Build specific runtime only
cargo build --release -p moonbeam-runtime
# Build TypeScript packages
pnpm i
pnpm build# Run all Rust tests
cargo test
# Run specific pallet tests
cargo test -p pallet-parachain-staking
# Run TypeScript integration tests (from test directory)
cd test
pnpm moonwall test dev_moonbase # Development tests
pnpm moonwall test smoke_moonbase # Smoke tests
# Run a single test file
pnpm moonwall test -d "test-contact" dev_moonbase D020512
# Run a single test
pnpm moonwall test -d "test-contact" dev_moonbase D020512T01# Rust linting and formatting
cargo clippy --release --workspace
cargo fmt -- --check
# TypeScript linting
pnpm check # Runs Biome linter# Using built binary
./target/release/moonbeam --dev --alice --sealing 6000 --rpc-port 9944
# Using Docker
docker run --network="host" moonbeamfoundation/moonbeam:v0.46.0 --dev --alice --sealing 6000 --rpc-port 9944Prerequisites: Install frame-omni-bencher from crates.io or Polkadot SDK
# Run runtime benchmarks (may need to update frame-omni-bencher path in script)
./scripts/run-benches-for-runtime.sh moonbase release
# The script uses frame-omni-bencher with these key parameters:
# --steps=50 --repeat=20 --wasm-execution=compiledThe runtime is the on-chain logic compiled to WASM. Moonbeam has three runtime variants:
- moonbeam: Production runtime for Polkadot
- moonriver: Production runtime for Kusama
- moonbase: TestNet runtime for Westend
Key architectural patterns:
- Pallet Structure: Custom logic is organized into pallets (e.g.,
pallet-parachain-staking) - Precompiles: EVM precompiled contracts in
/precompilesprovide native Substrate functionality to EVM - XCM Integration: Cross-chain messaging through XCM configuration in runtime
The client (/node) implements:
- RPC Layer: Custom RPC methods for Ethereum compatibility
- EVM Tracing: Debug and trace EVM execution
- Block Production: Collator logic for parachain block production
Tests are split into:
- Rust Unit Tests: In each pallet/module
- TypeScript Integration Tests: In
/testusing Moonwall framework - Smoke Tests: Minimal tests for quick validation
- Runtime ↔ EVM: Through precompiles and pallet-evm
- Client ↔ Runtime: Via runtime APIs defined in
runtime/common/src/apis - Substrate ↔ Ethereum: Through frontier pallets and custom RPC
| Network | Chain ID | Runtime | Purpose |
|---|---|---|---|
| Moonbeam | 1284 | moonbeam | Polkadot MainNet |
| Moonriver | 1285 | moonriver | Kusama parachain |
| Moonbase Alpha | 1287 | moonbase | Public TestNet |
| Development | 1281 | moonbase | Local development |
- New Pallet: Create in
/pallets, add to runtime'sconstruct_runtime! - New Precompile: Create in
/precompiles, register inprecompiles.rs - Runtime API: Define in
runtime/common/src/apis, implement in runtime - RPC Method: Add to
/client/rpc, expose in node service
- Use
ExtBuilderpattern for pallet unit tests - Use Moonwall's
DevModeContextfor integration tests - Test both Substrate and Ethereum interfaces when applicable
- Spec version in runtime when breaking changes
- Client version for node releases
- Precompile addresses are immutable once deployed
- Run
cargo fmt - Run
cargo clippy --release - Run
pnpm checkfor TypeScript - Ensure tests pass for modified components
- Add appropriate label:
B7-runtimenoteworthy,B5-clientnoteworthy, orB0-silent - Runtime changes need migration tests if applicable
- Breaking changes require runtime version bump