I am quite new with javascript web3 so don't be judge too hard.

I am using web3 version 1.0.0 beta.

I am taking the web3 reference this way:

if (typeof web3 !== 'undefined') {
    // If a web3 instance is already provided by Meta Mask.
    web3Provider = web3.currentProvider;
    web3 = new Web3(web3.currentProvider);
} else {
    // Specify default instance if no web3 instance provided
    web3Provider = new Web3.providers.HttpProvider('https://rinkeby.infura.io/v3/1b07b6c661304ef48005e16b43b7efa9');
    web3 = new Web3(web3Provider);

And then i am trying to get the contract reference:

var abi = [...];


var myContract = web3.eth.contract(abi, "0x2a2a7c53a6cc3d775e80c38d0fc446e73078902f");

.call({from:localAccount}, function(error, result){
    console.log('error: ' + error);

The error is: Cannot read property 'getPoll' of undefined

3 Answers 3


You aren't creating the contract object correctly. What version of Web3.js are you using? 1.0 or 0.2.x? Here is how you do it for each:

1.0: var myContract = new web3.eth.Contract(abi, "0x2a2a7c53a6cc3d775e80c38d0fc446e73078902f")

0.2.x: var myContract = web3.eth.contract(abi).at("0x2a2a7c53a6cc3d775e80c38d0fc446e73078902f")

I highly suggest you use 1.0 if you aren't yet, even though it's in beta.

  • I tried this " var myContract = web3.eth.contract(abi).at("0x2a2a7c53a6cc3d775e80c38d0fc446e73078902f");" and i get the same error. Commented Dec 4, 2018 at 16:52
  • And about the version, i think it is 1.0.0 beta. I am importing it this way: "<script src="cdn.jsdelivr.net/gh/ethereum/[email protected]/dist/…" integrity="sha256-nWBTbvxhJgjslRyuAKJHK+XcZPlCnmIAAMixz6EefVk=" crossorigin="anonymous"></script>" Commented Dec 4, 2018 at 16:54
  • That's not what I put though. Try what I put in my answer, var myContract = new web3.eth.Contract(abi, "0x2a2a7c53a6cc3d775e80c38d0fc446e73078902f") Glad to hear you're using 1.0 though!
    – natewelch_
    Commented Dec 4, 2018 at 17:11
  • I made it work, apparently web3 version was 0.2.x taken from metamask. Now that i am using 1.0.0 it works. At least that part... Commented Dec 11, 2018 at 13:16

Change this:


To this:

new web3.eth.Contract
  • 1
    “Web3.eth.Contract is not a constructor” or something similar Commented Dec 4, 2018 at 17:09
  • @AlexandruSandu: web3, not Web3! Commented Dec 4, 2018 at 17:14
  • I know, i tried that but i wrote this comment form my phone and misspelled it Commented Dec 4, 2018 at 17:15

You must write it in this form:

if getPoll method is view or pure:

    if (! error)

and if the method is changing the state variables use send method, instead of call.

option is a variable that clarify the transaction specifications, like:

var option = {from: 0x...};
  • Still undefined Commented Dec 8, 2018 at 17:04
  • Is your ABI code correct? Commented Dec 8, 2018 at 18:01
  • Yes, i am using the same json with the truffle-contract method of getting the contract, which works fine (“$.getJSON(yadayadayada)”) Commented Dec 8, 2018 at 18:10

Your Answer

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

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