Foundry Cheatcode Generator
Generate and explore Foundry testing cheatcodes with examples
Available Cheatcodes (17)
Foundry Cheatcodes: Special testing functions that manipulate the EVM state. Use these in your Foundry tests to control time, impersonate accounts, mock calls, and more. All cheatcodes are prefixed with
vm.1. What are Foundry Cheatcodes?
Cheatcodes are special functions in Foundry that allow you to manipulate the EVM state during tests. They enable time travel, account impersonation, balance manipulation, and more.
2. How does it work?
Common Use Cases
Pranking: Impersonate any address with vm.prank() or vm.startPrank(). Balance: Set ETH balances with vm.deal(). Time: Control block.timestamp with vm.warp(). Mocking: Mock external calls with vm.mockCall().
3. Examples
Impersonate USDC Transfer (Mainnet)
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
// Binance wallet
vm.prank(0xF977814e90dA44bFA03b6295A0616a897441aceC);
IERC20(usdc).transfer(recipient, 1000e6);Uniswap Liquidity Testing
// Simulate 30 days passing
vm.warp(block.timestamp + 30 days);
// Give ETH to alice
vm.deal(alice, 100 ether);
router.swapExactETHForTokens{value: 1 ether}(
0,
path,
address(this),
block.timestamp
);Aave Flashloan Mock Test
address aave = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9;
vm.mockCall(
aave,
abi.encodeWithSelector(ILendingPool.flashLoan.selector),
abi.encode(true)
);
vm.expectCall(
aave,
abi.encodeWithSelector(ILendingPool.flashLoan.selector)
);
lendingPool.flashLoan(token, amount, data);