0

For whatever reason, when I attempt to set an instance of a contract in a javascript file, I get the following message in my console:

Uncaught TypeError: web3.eth.Contract is not a constructor 

At first, I suspected I had a problem with properly setting my Web3 instance, but when I run:

console.log(web3);

The console shows that I the web3 instance is set.

I try and set my the contract instance using the following code:

const myContract = new web3.eth.Contract([//json array]);

Any tips for solving this?

3
  • 1
    This is for v1.x, you're probably still on v0.x. You can check it via npm ls web3. For v0.x, remove the new and change Contract with an upper-case C to contract with a lower-case c. Jul 8, 2019 at 15:19
  • Thank you goodvibration, that solved my problem. How do I give you credit for the answer? Jul 9, 2019 at 13:27
  • 1
    I added it as an answer, so you can give it a credit... Jul 9, 2019 at 14:04

1 Answer 1

0

This is for v1.x, you're probably still on v0.x.

You can check it via npm ls web3.

For v0.x, remove the new and change Contract to contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.