[Ethereum] TypeError: web3.eth.Contract is not a constructor (What is the reason ?)

contract-invocationweb3js

I always use following command to create a contract instance without any problem :

var contractInstance = new web3.eth.Contract(abi, '0xe1623AAf57fCbe260F022404C730ae32aebe39F6');

However, when currently I use this command, I receive following error :

TypeError: web3.eth.Contract is not a constructor

What is the reason ?

Best Answer

TypeError: web3.eth.Contract is not a constructor

This is a generic javascript error: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_constructor

You call a 'new' on an object ('web3.eth.Contract') without a constructor.

It looks like your jumping from web3 versions.

In web3 < 1.0, this is the syntax (lowercase c, no 'new'):

var MyContract = web3.eth.contract(abiArray, contractAddress);
var version = web3.version.api; // "0.2.0"

In web3 1.0 (not ready for production yet) this is the syntax (uppercase C, 'new'):

var MyContract = new web3.eth.Contract(abiArray, contractAddress);
var version = web3.version; // "1.0.0"