This project demonstrates how to test 1inch swaps locally using ethers v6 in a basic Hardhat project.
This project contains a single script that will do the following on a local fork of Mainnet:
- Move WETH from a large holder to a local wallet
- Approve the 1inch v6 router to spend the local wallet's WETH
- Swap WETH for USDC through the 1inch v6 router
Install the project
npm install
Run a local fork of Mainnet from your terminal (Infura or Alchemy are good RPC options)
npx hardhat node --fork <mainnet_rpc_url>
With your local fork running, open up a second terminal and run the following from the root directory of the project:
npx hardhat run scripts/1inchSwap.js --network localhost
This second terminal will connect to your local hardhat fork of Mainnet and simulate the swap