Skip to main content
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:

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:
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:

Set custom chain ID

Override the chain ID if needed:

Adjust block time

Set custom block time (default is instant mining):

Test the fork

Connect with cast

Verify your fork is running:
Or use curl to retrieve the HYPE token total supply off the local fork:

Check account balances

View the balance of any Hyperliquid address:

Impersonate accounts

Impersonate any account for testing:
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

Last modified on April 13, 2026