How to use Uniswap Interface in Hardhat


2 min read

For some extraordinary reasons, you need to make use of uniswap to swap assets, perform some liquidity operations, or any other cool thing uniswap has to offer. You probably started off from remix IDE, and now you want to bring it down to your local machine to compile and test properly and more conveniently using the hardhat framework.

This might be new to you but currently, the hardhat framework does not support HTTPS import, this is what I mean.

pragma solidity 0.8.4;

import "";

you would end up with an error when you try to compile using npx hardhat compile , and end up with a bloody terminal with messages like :

Error HH406: Invalid import from contracts/Swap.sol. Hardhat doesn't support imports via HTTPS.


The solution is very simple, you would need to navigate to the GitHub URL, copy the contents and also make sure to include the files that might also be imported by the IUniswapV2Router02.sol file.

So instead of using HTTPS which works fine using remix IDE, do something like this.

  • Create IUniswapV2Router02.sol file
  • Navigate to the GitHub repo
  • Copy the contents
  • Paste inside the newly created file.
  • You would notice that the content also has a dependency, so go ahead and also fetch the files content and you should be good to go.


Happy Hacking