How to use Uniswap Interface in Hardhat

Johnson awah Alfred's photo
Johnson awah Alfred
ยทApr 18, 2022ยท

2 min read

Subscribe to my newsletter and never miss my upcoming articles

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 "https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol";

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 https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router02.sol from contracts/Swap.sol. Hardhat doesn't support imports via HTTPS.

Solution

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.

Bye!!

Happy Hacking

ย 
Share this