there is a contract on github. I need to inherit it/ So how can I do it? Using import isn't available how I unnderstand..


2 Answers 2


You could just import from the GitHub link, but in your case there is an nom package containing that contract already so you could:

  1. Run npm i @uniswap/v2-periphery on your project.
  2. Import it like this on your .sol file: import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol';

Good Day

One Can Do the Following below your pragma statement

Add The Following

import "./interfaces/IUniswapV2Router01.sol";


import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol';

above your constructor declare the following

 address public routerContract;

in the Constructor you can do the following

 constructor(address routerContractAddr){
        routerContract= routerContractAddr;

in order to use the interface functions one can do the following


remember to deploy your contract with the correct Uniswap Router Address

an example of a deploy script using hardhat is illustrated below

 module.exports = async ({ ethers, getNamedAccounts, deployments }) => {
  const { deploy } = deployments;
  const { deployer } = await getNamedAccounts();
  await deploy("YourContract", {
    from: deployer,
    deterministicDeployment: false,
    log: true,

module.exports.tags = ["YourContract"]; 

I Really Hope That My Answer Provides Clarity

Thank You

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.