So im trying to write a smart contract that involves using Uniswap. I would like to test my smart contract and was looking into setting up uniswap on my local ganache server, but as I am new, a few things are not very clear.

I found a medium article that explained how this is done:

-Deploy the UniswapExchange contract

-Deploy the UniswapFactory contract

-Initialize the UniswapFactory (with the UniswapExchange address)

-Deploy the Dai ERC20 token contract

-Deploy the Dai UniswapExchange contract (using the Dai address)

-Approve the Dai UniswapExchange contract to transfer Dai

-Add liquidity to the Dai UniswapExchange contract

So I want to start off by deploying the uniswapexchange and uniswap factory contract. When I go to uniswapV2factory on uniswap github it has 2 import functions on the top, namely:

import './interfaces/IUniswapV2Factory.sol';
import './UniswapV2Pair.sol';

Now these point toward a folder that I do not have on my local computer. When importing the UniswapV2Factory.sol contract to my own contract, do I have to also seperately download the interface and UniswapV2Pair and put them in the folder as stated in the contract I am importing? Also, on a local ganache server the uniswap factory contract are not up, so I have to deploy them myself, but if I would deploy my contract on a testnetwork, would just using an interface and the contract address suffice. If so, what are the benefits of either importing the contract or using an interface? As fas as Im aware an interface doesnt inherit and importing does? For this reason I read that some people prefer to use a contract instead of an interface, when should I go for an interface and when should I use a contract to interact with other smart contracts?

My last question is, the UniswapV2Factory.sol contract uses solidity 0.5.16, but its written as

pragma solidity =0.5.16;

does this mean that my contract where I want to call the functions from this contract has to be written in 0.5.16 as well?

Thanks in advance!

  • 2
    If you're new I strongly recommend against starting with deploying uniswap. There are various difficult parts, it's not the easiest project to clone. Two of the first problems you'll face are 1) incompatible Solidity versions 2) Getting the whole deployment pipeline to work Nov 8, 2020 at 19:03
  • and why not truffle against mainnet over infura?
    – Isa O.
    Jul 4, 2021 at 13:52

1 Answer 1


have you considered using Hardhat to fork mainnet so you can test your contracts against a more real-world version of uniswap?

Take a look at this. https://hardhat.org/guides/mainnet-forking.html

I use this approach when testing contracts that involve creating pairs, adding/removing liquidity, arbitrage etc.

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.