Configure a local Anvil node with specific parameters:
Copy
Ask AI
.withLocalNode({ // Required: Chain ID for the local network chainId: 1337, // Optional: Fork from an existing network forkUrl: "https://mainnet.base.org", // Optional: Fork from a specific block forkBlockNumber: BigInt("12345678"), // Optional: EVM hardfork to use hardfork: "cancun", // Optional: Port range for parallel testing minPort: 9545, maxPort: 9645,})
.withNetwork({ name: "My Custom Network", chainId: 12345, symbol: "ETH", rpcUrl: "https://my-rpc-endpoint.com", // This is ususally localhost:8545 since the onchaintestkit network interceptor listens to this port and forwards RPC requests sent to this port to the anvil node isTestnet: true, // Optional: mark as testnet})
import { createOnchainTest } from '@coinbase/onchaintestkit';import { metamaskWalletConfig } from './config/metamask.config';const test = createOnchainTest(metamaskWalletConfig);test('my test', async ({ page, metamask, node }) => { // Your test code here console.log(`Local node running on port: ${node?.port}`);});