poma / hardhat-etherscan-abi

MIT License
13 stars 10 forks source link

Typescript : Propety 'getVerifiedContractAt' does not exist #1

Open massun-onibakuchi opened 3 years ago

massun-onibakuchi commented 3 years ago

I try some test. I added this to my hardhat.config.ts: import "hardhat-etherscan-abi" Then I try to a following test.

import { ethers, waffle } from "hardhat";
import hre from 'hardhat';

    before(async function () {
        bank = await ethers.getVerifiedContractAt(BANK_ADDRESS);
    });

It give me a error ,

Property 'getVerifiedContractAt' does not exist on type 'typeof import("/Users/user-name/ethereum/idle-alphahomora-integration/node_modules/ethers/lib/ethers") & HardhatEthersHelpers'.

26         bank = await ethers.getVerifiedContractAt(BANK_ADDRESS);
                               ~~~~~~~~~~~~~~~~~~~~~

I also try the same test in js, it worked properly. @poma

ghost commented 3 years ago

That's what I did in ts

const hre = require("hardhat");
vault = await hre.ethers.getVerifiedContractAt(BANK_ADDRESS);
clacladev commented 3 years ago

I have the same problem. I have created a HH js script that is supposed to cache the ABIs of a series of contracts. But the function does not exists:

require('hardhat-etherscan-abi');
const hre = require("hardhat");

async function fetchAndSaveABI(contractName, address) {
  const abi = await hre.ethers.getVerifiedContractAt(address);
  // stuff
};

I tried a series of things, without success.

poma commented 3 years ago

I don't know typescript well enough to fix this. Maybe someone can help?

clacladev commented 3 years ago

The issue was that I was trying to create a script in the HH scaffold. But when I converted it into a HH task, then it worked correctly.

pasevin commented 3 years ago

@poma I tried looking into it. And from what I've gathered, because you're trying to extend the hre.ethers, with this plugin, it's required much more, than just extendEnvironment. If you look at hardhat-deploy-ethers plugin you will understand.

It's easier to just extend hre with new functions via extendEnvironment.

So currently it's impossible for me to use this plugin (at least in Typescript), and I don't have so much time to rewrite it...

poma commented 3 years ago

It seems like hardhat-deploy-ethers is doing similar stuff: https://github.com/wighawag/hardhat-deploy-ethers/blob/main/src/internal/index.ts#L27 except that my code seems to capture previous ethers on initialization instead of inside lazyObject init. I'll try to experiment with it.

pasevin commented 3 years ago

I tried to do it in their way, but then one thing led to another... Looks like you have to duplicate and extend the whole eth.ethers just to add your custom functions.

I think if you look at this line: https://github.com/wighawag/hardhat-deploy-ethers/blob/f4990b24fd2eb6865d96a53c84b5eab0f094495a/src/internal/type-extensions.ts#L14 it limits the type to ethers and HardhatEthersHelpers, which leads to: https://github.com/wighawag/hardhat-deploy-ethers/blob/f4990b24fd2eb6865d96a53c84b5eab0f094495a/src/types/index.ts#L24

I didn't have enough time to decide where the extension of hre.ethers should happen so to adhere to the hardhat plugin guidelines. The hardhat-deploy-ethers overrides the whole thing from scratch it seems. Basically replacing the original one. It's meant to be used in place of the original hre.ethers.

P.S. but again I only spent 30 minutes on this whole plugin stuff :))

poma commented 3 years ago

Is there a way to extend HardhatEthersHelpers maybe? I've tried to experiment in typescript branch but no luck so far.

pasevin commented 3 years ago

Have no idea... they have a discord server with a channel for plugin development, maybe you can ask there: https://discord.gg/unHHhmK92a

Metroxe commented 2 years ago

Anyone ever find a solution to this?