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.
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.
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
So instead of using HTTPS which works fine using remix IDE, do something like this.
- 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.