0

I wanna get UniswapV2Router02 deployed on Fantom network.

UniswapRouter = await ethers.getContractAt(
      "UniswapV2Router02",
      "0xf491e7b69e4244ad4002bc14e878a34207e38c29"
);

But I get the following error. HardhatError: HH700: Artifact for contract "UniswapV2Router02" not found.

Please help me!

1 Answer 1

0

ethers.getContractAt is not ether js native method. Instead it is the variant of hardhat-ethers.

You should use ether.js method.

First go to, fantom scan and take the contract abi and save it in router02.json file.

Then require it to the main file with

const {ABI} = require("./router02.json")

require("dotenv").config();

const { ALCHEMY_API_KEY } = process.env;

const provider = new ethers.providers.JsonRpcProvider(
`[FantomAPiURL]/${ALCHEMY_API_KEY}`
 );

const address = "0xf491e7b69e4244ad4002bc14e878a34207e38c29";

const contract = new ethers.Contract(address, ABI, provider);

That is it. You will get contract instance there and you can function as you like.

If you have any doubts regarding .env file. Look at this answer of mine, I explained it clearly here.

Comment if you don't understand anything.

5
  • Thanks. I must provide "provider"? What if I ignore "provider" parameter? Sep 21, 2022 at 10:06
  • Without provider, you cannot talk to blockchains. Providers are in fact node providers. Only with the help of them you can query or write the transactions. Go to alchemy and create an account. It is pretty much self-explantory. But if you have any doubts, ask me.
    – Ad-h0c
    Sep 21, 2022 at 10:12
  • I'm gonna create app on Alchemy but I can't find Fantom on "CHAIN" option. Sep 21, 2022 at 10:16
  • I am sorry. I have never tried Fantom so I wasn't sure. But here, quick node can help you! [quicknode.com/chains/…
    – Ad-h0c
    Sep 21, 2022 at 10:20
  • You should use ether.js method. - why? If you're using hardhat-ethers then getContractAs is certainly available.
    – Madbreaks
    Nov 16, 2022 at 21:51

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.