This guide demonstrates how to fork the Hyperliquid EVM chain using Foundry’s Anvil to create a local development environment for testing smart contracts and dApps.

Prerequisites

Before starting, ensure you have:
  • Foundry installed
  • A Hyperliquid EVM RPC endpoint from Chainstack
  • Basic knowledge of Foundry and smart contract development

Why fork Hyperliquid EVM?

Forking allows you to:
  • Test smart contracts against the actual Hyperliquid EVM state
  • Simulate transactions without spending real funds
  • Debug and develop dApps in a controlled environment
  • Test interactions with deployed contracts on Hyperliquid

Start a forked instance

Use Anvil to fork the Hyperliquid EVM mainnet:
anvil --fork-url YOUR_CHAINSTACK_HYPERLIQUID_ENDPOINT
Replace YOUR_CHAINSTACK_HYPERLIQUID_ENDPOINT with your actual Chainstack Hyperliquid EVM endpoint.
The Hyperliquid HyperEVM mainnet uses chain ID 999. Anvil will automatically inherit this when forking.

Configure fork options

Fork from a specific block

To fork from a specific block height:
anvil --fork-url YOUR_CHAINSTACK_HYPERLIQUID_ENDPOINT --fork-block-number 13276400

Set custom chain ID

Override the chain ID if needed:
anvil --fork-url YOUR_CHAINSTACK_HYPERLIQUID_ENDPOINT --chain-id 31337

Adjust block time

Set custom block time (default is instant mining):
anvil --fork-url YOUR_CHAINSTACK_HYPERLIQUID_ENDPOINT --block-time 1

Test the fork

Connect with cast

Verify your fork is running:
cast block-number --rpc-url http://localhost:8545
Or use curl to retrieve the HYPE token total supply off the local fork:
curl --request POST \
  --url 127.0.0.1:8545 \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "method": "eth_call",
  "params": [
    {
      "to": "0x5555555555555555555555555555555555555555",
      "data": "0x18160ddd"
    },
    "latest"
  ],
  "id": 1
}'

Check account balances

View the balance of any Hyperliquid address:
cast balance 0xYourAddress --rpc-url http://localhost:8545

Impersonate accounts

Impersonate any account for testing:
cast rpc anvil_impersonateAccount 0xAccountToImpersonate --rpc-url http://localhost:8545
Remember that forked state is ephemeral. Any transactions or state changes exist only in your local fork and don’t affect the actual Hyperliquid network.

Best practices

1

Always fork from a recent block to ensure state relevance
2

Use deterministic testing by forking from specific blocks
3

Save fork state when testing complex scenarios
4

Monitor your Chainstack endpoint usage to avoid rate limits

Conclusion

Forking Hyperliquid EVM with Foundry provides a powerful development environment for testing smart contracts and dApps. This approach allows you to interact with actual on-chain state without risking real funds or affecting the live network.

Next steps