how to define a web3 contract type in typescript

Viewed 1693

So I am trying to define a type of web3 contract with typescript. We know that a web3 contract is defined in the form that

var myContract = new web3.eth.Contract(contractABI, contractAddress)

My question is that How to define a type of such contract so that the following code is possible

function myFunction(someContract: contract){...}

Any feedback will be appreciated.

1 Answers

In case you don't have web3.js:

npm i web3

To get the type, paste this in imports:

import { Contract } from "web3-eth-contract"

Now you can use Contract as a type

function myFunction(someContract: Contract) {...}
Related