Testing Uniswap Locally – How to Test Uniswap Contracts Locally with Ganache

ganachesoliditytestinguniswap

So far I developed smart contracts in Solidity using Ganache. I didn't have to use Uniswap in any way.

Now I'd like to use Uniswap to put some of my ERC-20 token as liquidity. I started reading the Uniswap docs, but things are a bit unclear to me. Below are my sub-questions related to locally testing Uniswap:

  1. How do I locally set up a test environment for Uniswap? So far I was using Ganache, but from what I read here hardhat would be preferred. Can anyone quickly explain what do I have to do to set it up locally (with or without Ganache)?
  2. Under the title Importing Ethers and the V3 SDK in this tutorial, where do I put the code? In what file does the code go? I'm a bit confused there.

Thank you in advance!

Best Answer

The simplest solution would be to locally run npx hardhat node in “mainnet fork” mode. When your scripts interact with an Ethereum address on http://localhost:8545, hardhat-node goes and fetches the code/state from the same address on the mainnet, and makes it appear as if you were interacting with the actual mainnet. Except that you’re not, so it’s free of charge.

Related Topic