Web3.js: web3.eth.Contract is not a constructor at HTMLDocument

Created on 17 Oct 2019  路  3Comments  路  Source: ChainSafe/web3.js

""This is exactly where I am getting error."

               contract = new web3.eth.Contract(abi, address);

                contract.methods.getBalance().call().then(function(bal)
                {
                    $('#details').html(bal);
                })

AND THIS IS THE ERROR::
(index):53 Uncaught TypeError: web3.eth.Contract is not a constructor
at HTMLDocument. ((index):53)
at n (jquery.min.js:2)
at Object.fireWith (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
at HTMLDocument.B (jquery.min.js:2)
(anonymous) @ (index):53
n @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
B @ jquery.min.js:2
web3

more information needed

Most helpful comment

@praveengupta0895:
Your browser most likely imports an older version of Web3.js - 0.x instead of 1.x, where you should use contract = web3.eth.contract instead of contract = new web3.eth.Contract (i.e., without new and with a lower-case c instead of an upper-case C).
You may run console.log(web3.version) from your browser in order to verify this.

All 3 comments

Thanks for opening this issue! Could you please provide the whole code in a repository on GitHub or in a gist file? and what version of web3.js are you using?

@praveengupta0895:
Your browser most likely imports an older version of Web3.js - 0.x instead of 1.x, where you should use contract = web3.eth.contract instead of contract = new web3.eth.Contract (i.e., without new and with a lower-case c instead of an upper-case C).
You may run console.log(web3.version) from your browser in order to verify this.

@barakman
Thanks, this worked for me.

Was this page helpful?
0 / 5 - 0 ratings