Skip to content

Not getting types from Contract using Typescript, Hardhat & Typechain #2417

Answered by zemse
rrriki asked this question in Q&A
Discussion options

You must be logged in to vote

@rrriki new ethers.Contract(marketContractAddress, Market.abi, provider); generates methods during runtime and hence typescript does not know the functions. Due to this reason, typechain has an extended version of ethers.Contract class for every kind of contract which adds typings of your methods. So you have to use them.

TLDR; You have to import from the typechain directory

import { MarketContract__factory } from '../../typechain';
const marketContract = MarketContract__factory.connect(marketContractAddress, provider);`

You may go through the docs for using ethers v5 target in typechain.

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@rrriki
Comment options

Answer selected by rrriki
Comment options

You must be logged in to vote
1 reply
@zemse
Comment options

zemse May 7, 2022
Collaborator

Comment options

You must be logged in to vote
1 reply
@zemse
Comment options

zemse Aug 14, 2022
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants