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!

2 Answers 2


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.

  • Is there a way to set the price of a token (for testing purposes) Commented Apr 8 at 17:17

You need to fork the blockchain. You can set up a forked chain by connecting ganache to a node from a service like alchemy or infura or moralis. I personally like alchemy.

Once connected your code will use the previous blocks from the node and use ganache to generate the most recent test block

It will also have all the contracts deployed to that chain. Just point your script to the address of uniswap

As for question 2 i don't use javascript but it looks like it's importing ethers from the ethers.js package and using ethers to interact with the pair contract. This would go in a js script and not in your smart contract

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.