Develop and test Uniswap v4 Hooks with minimal interfaces for the swap lifecycle (pool creation, liquidity provision, and swapping)
inspired by scaffold-eth
✅ Template hook with deployment commands
✅ User interfaces for: pool creation, liquidity creation, and swapping
✅ Local network (anvil) with predeployed Uniswap v4
✅ Testnet support
✅ Foundry (hardhat support coming later)
Please update foundry.toml to use the linux solc
Mac users do not need to change anything by default
forge install
cd nextjs/
npm install
cp .env.example .env
See Environment additional setup
-
Start the local network, with v4 contracts predeployed
# root of the repository cd scaffold-hook/ npm run anvil
-
Deploy the template hook
# root of the repository cd scaffold-hook/ forge build npm run deploy:anvil
-
Update wagmi.config.ts with the hook address from run-latest.json
-
Regenerate react hooks, addresses, and ABIs
cd nextjs/ npm run wagmi
-
Start the webapp
cd nextjs/ npm run dev
Modifying the file name, contract name, or hook flags will require configuration:
Renaming -- update .env
# Hook Contract, formatted: <filename.sol>:<contractName>
HOOK_CONTRACT="Counter.sol:Counter"
Changing hook flags -- update .env and ensure getHookCalls()
is in agreement
# in .env
# Hook Flags
BEFORE_SWAP=true
AFTER_SWAP=true
BEFORE_MODIFY_POSITION=true
AFTER_MODIFY_POSITION=true
BEFORE_INITIALIZE=false
AFTER_INITIALIZE=false
BEFORE_DONATE=false
AFTER_DONATE=false
// in Hook Contract
function getHooksCalls() public pure returns (Hooks.Calls memory) {
return Hooks.Calls({
beforeInitialize: false,
afterInitialize: false,
beforeModifyPosition: true,
afterModifyPosition: true,
beforeSwap: true,
afterSwap: true,
beforeDonate: false,
afterDonate: false
});
}
Ensure your wallet is funded with testnet gas (ETH)
-
npm run deploy:anvil
-
npm run deploy:goerli
-
npm run deploy:arbitrum-goerli
-
npm run deploy:arbitrum-sepolia
-
npm run deploy:optimism-goerli
-
npm run deploy:base-goerli
-
npm run deploy:sepolia
-
npm run deploy:scroll-sepolia
-
npm run deploy:polygon-mumbai
-
npm run deploy:polygon-zkevm-testnet
While scaffold-hook
ships solmate's MockERC20
on local and testnet, you can provide your own custom tokens:
- define them in wagmi.config.ts, and regenerate the codegen:
npm run wagmi
- import the generated addresses and edit
TOKEN_ADDRESSES
- define the hook in wagmi.config.ts, and regenerate the codegen:
npm run wagmi
- import the generated types and edit
DEBUGGABLE_ADDRESSES
ANVIL_FORK_URL
: RPC URL for anvil fork modeETHERSCAN_API_KEY
: Your Etherscan API KeyFORGE_PRIVATE_KEY
: The private key of the wallet for testnet deployments
To learn more about Next.js, Foundry or wagmi, check out the following resources:
- Foundry Documentation – learn more about the Foundry stack (Anvil, Forge, etc).
- wagmi Documentation – learn about wagmi Hooks and API.
- wagmi Examples – a suite of simple examples using wagmi.
- @wagmi/cli Documentation – learn more about the wagmi CLI.
- Next.js Documentation learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.