question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typechain ethers-v5 inclusion of hardhat-ethers

See original GitHub issue

In the newest version of typechain, typechain ethers-5 target include types for the plugin hardhat-ethers

This pose problem for plugin that are alternative to hardhat-ethers like hardhat-deploy-ethers which have different function signature, but use the same hre.ethers object

An option to at least disable hardhat-ethers type generation would be good. AFter all the ethers v5 target should focus on ethers itself.

An alternative would be to create a specific hardhat ethers target

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
haydenyoungcommented, Mar 21, 2022

As an outsider, I understand the issue results from the hardhat getContract* types being hardcoded; the hardcoded types are actually in typechain/ethers-v5, dist/congen/hardhat to be precise.

Because hardhat-deploy-ethers exposes new methods (in particular getContract()) and because typechain/ethers-v5 is hardcoding the ethers types, the getContract types are not available and, hence, typechain has no idea what getContract is returning (because the type definition never gets created).

Currently, the hardhat-deploy-ethers plugin deletes hardhat.d.ts which results in all of the getContract* functions having no type definitions.

Is there a way to create the types “on-the-fly” somehow, in order to take advantage of the extended getContract() function? Happy to help if I know I’m interpreting the problem correctly and can be given some guidance in how to potentially solve this issue.

1reaction
luisnaranjo733commented, May 21, 2022

As an outsider, I understand the issue results from the hardhat getContract* types being hardcoded; the hardcoded types are actually in typechain/ethers-v5, dist/congen/hardhat to be precise.

Because hardhat-deploy-ethers exposes new methods (in particular getContract()) and because typechain/ethers-v5 is hardcoding the ethers types, the getContract types are not available and, hence, typechain has no idea what getContract is returning (because the type definition never gets created).

Currently, the hardhat-deploy-ethers plugin deletes hardhat.d.ts which results in all of the getContract* functions having no type definitions.

Is there a way to create the types “on-the-fly” somehow, in order to take advantage of the extended getContract() function? Happy to help if I know I’m interpreting the problem correctly and can be given some guidance in how to potentially solve this issue.

So in theory I think it’s possible for hardhat-deploy to ship with Typescript module definition likes (*.d.ts) that could “brute force” overwrite the types but that’s pretty messy

I think it would be better if typechain could offer a way to de-couple itself from the hardhat ethers plugin to support forked plugins (mainly hardhat-deploy). The need for this is growing as other template projects (such as scaffold-eth) now depend internally on hardhat-deploy (which is honestly just a better version that the built in HH plugin).

Unrelated question - are there plans for hardhat-deploy to get unforked with the official HH plugin at some point? Would make the need for fixing this in typechain a lot more clear and present.

One final random note - I’m working around this typechain issue in my hardhat-deploy project by explicitly setting the generic type per the suggestion here. It’s a minor nuisance, but it’s a bummer because Typechain is so cool and it’s so close to just working for hardhat-deploy projects too

https://github.com/wighawag/hardhat-deploy-ethers/issues/23#issuecomment-1101040259

Read more comments on GitHub >

github_iconTop Results From Across the Web

@typechain/ethers-v5 - npm
@typechain/ethers-v5. TypeScript icon, indicating that this package has built-in type declarations. 10.2.0 • Public • Published 13 days ago.
Read more >
Feature to add a Contracts object to typechain #370 - GitHub
So it's a bit of a pain to use the lib as is with hardhat. First I need to get the SystemFactory, then...
Read more >
The New Solidity Dev Stack: Hardhat + Ethers + Waffle + ...
TypeChain is a really cool tool that gives you a full typed interface for your smart contracts. Once it's set up we can...
Read more >
How to deploy your first smart contract on Ethereum with ...
Tagged with ethereum, solidity, web3, hardhat. ... yarn add --dev typechain @typechain/hardhat @typechain/ethers-v5.
Read more >
TypeChain: TypeScript Bindings for Ethereum Smart Contracts
Under the hood, eth-sdk relies on TypeChain . Usage. CLI. Note: If you use hardhat just use hardhat plugin. typechain --target=(ethers-v5|truffle- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found