hii)) Somebody I need rapid help ;)
I use hardhat and try to connect to uniswap router contract from task. For this I'm trying to use
hre.ethers.getContractAt(
abi,
contract,
signer
);
where
abi - is abi =))
contract - it's a contract address
signer - a signer
So when I start task I get an error
Error HH700: Artifact for contract - yes I don't have any artifact for this contract because I don't compile it'' It's a public one. How to resolve this issue?
Apr 20, 2022, 7:25 PM
any suggestions?
Apr 20, 2022, 7:32 PM
Even if it's a public contract you need to provide the abi so that the compiler knows which functions that contract has.
Either you compile the contract or you download the abi and put it in a file in the right location so that the code can pull it
Either you compile the contract or you download the abi and put it in a file in the right location so that the code can pull it
Apr 20, 2022, 7:34 PM
Yes I did it. I have abi which I pass to getContractAt as a first argument
Apr 20, 2022, 7:35 PM
Hi. Have you found and imported uniswap router abi json file? You need it to access the deployes router contract
Or you can create a contract that use router just like me
Apr 20, 2022, 7:36 PM
So, here is my code
const fs = require("fs");
const path = require("path");
const parsed = JSON.parse(
fs.readFileSync(path.join(__dirname, "./Router.json"))
);
const abi = parsed.result;
const router2: ethers.Contract = await hre.ethers.getContractAt(
abi,
contract,
signer
);
Router.json it's a ABI
const fs = require("fs");
const path = require("path");
const parsed = JSON.parse(
fs.readFileSync(path.join(__dirname, "./Router.json"))
);
const abi = parsed.result;
const router2: ethers.Contract = await hre.ethers.getContractAt(
abi,
contract,
signer
);
Router.json it's a ABI
Apr 20, 2022, 7:36 PM
What the error exactly is?
Apr 20, 2022, 7:38 PM
when I call my task I get error
I little upper I send error screen
Apr 20, 2022, 7:38 PM
I think that you pass abi in a wrong place. getContractAt expects atrifact name
Apr 20, 2022, 7:40 PM
there is 2 functions, one get Artifact name, another abi. But it seems I use it wrong
https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html#helpers
Apr 20, 2022, 7:41 PM
It seems that you pass string instead of json object
Apr 20, 2022, 7:41 PM
hmmmm.. probably
Apr 20, 2022, 7:41 PM
Try to decode json abi
Apr 20, 2022, 7:41 PM
huh man, you save my evening, good bless you!
Apr 20, 2022, 7:44 PM
What the hell is a contract variable?
Apr 21, 2022, 3:13 AM
It's an ABI
Apr 21, 2022, 5:01 AM