1

I deployed a contract and would like to watch for events on that contract.

var access_manager_erc20_abi = require('./AccessManagerERC20_abi.js');  //To read the abi.

//In this js file i export abi into a variable and use it while creating instance of contract below.

//Smart contract address

var AccessManagerERC20ContractAddress = "0x3267ced1528c7eabe69bd129b3d0faf9986d6b55";

//creating instance of contract

AccessManagerERC20Contract = await new web3.eth.Contract(access_manager_erc20_abi,AccessManagerERC20ContractAddress);

watching for events, followed documentation from https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#events

AccessManagerERC20Contract.events.getAccessERC20Event({
    filter: {_producerGatewayID:acc[1]}}, function(error, event){ console.log(event); })
.on('data', function(event){
    console.log(event); // same results as the optional callback above
})
.on('changed', function(event){
    // remove event from local database
})
.on('error', console.error);

when I try to execute this piece of code, it says

TypeError: AccessManagerERC20Contract.events.getAccessERC20Event is not a function

Can someone help me please. I am using web 3 v1.0.0. beta.

Thanks in advance

5
  • Is your event actually called getAccessERC20Event? Could you share your contract code or ABI?
    – user19510
    Commented Apr 25, 2018 at 14:04
  • Try AccessManagerERC20Contract.getAccessERC20Event().watch(function (error, result){ //do something with results here })
    – Gabe
    Commented Apr 25, 2018 at 14:23
  • It would be helpful to see your ABI. Maybe it isn't in proper JSON format? Commented Apr 25, 2018 at 15:57
  • @smarx, yes the event name is correct. Here is the ABI code github.com/katkol/Share/blob/master/AccessManagerERC20_abi.js
    – K Kolluru
    Commented Apr 25, 2018 at 20:07
  • @Gabe I get similar error with this code as well, TypeError: AccessManagerERC20Contract.getAccessERC20Event is not a function
    – K Kolluru
    Commented Apr 25, 2018 at 20:15

1 Answer 1

1

I will just point to another question that you just asked because this seems to be the same problem:

using abi generated by truffle in DApp

If you look at your abi-file it is the same problem and you need to call:

AccessManagerERC20Contract = await new web3.eth.Contract(access_manager_erc20_abi.abi,AccessManagerERC20ContractAddress);
2
  • Hi, after changing the abi part the event also worked. Cannot point out the reason behind though.
    – K Kolluru
    Commented Apr 26, 2018 at 11:33
  • Also I am using ws provider instead of http.
    – K Kolluru
    Commented Apr 26, 2018 at 11:45

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.