Cannot read property 'contract' of undefined. Node api interacting with smart contract

by SwimmingG   Last Updated January 13, 2018 22:28 PM

Hi I'm trying to interact with an Ethereum smart contract from my node js api.

My controller function is as follows:

var web3 = require('web3');

module.exports.getTokenBalance = function(req, res) {
var abi = //long ABI
var MyContract = web3.eth.contract(abi);

  // initiate contract for an address
  var myContractInstance = MyContract.at('...');
  myContractInstance.balanceOf.call('addr', function(err, data) {

  }
}

I'm using the web3@0.20 package. When I try to call this API function I get the following error "Cannot read property 'contract' of undefined."

Am I missing something stupid?



Related Questions





Gas limit and price in send raw transaction

Updated September 03, 2017 21:28 PM