Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

events.myevent is not working #2954

Closed
taducquang opened this issue Jul 18, 2019 · 1 comment
Closed

events.myevent is not working #2954

taducquang opened this issue Jul 18, 2019 · 1 comment

Comments

@taducquang
Copy link

Description

Subscribing to an event of a contract on mainnet using infura throws an error and not working. I don't know if i miss something.
I did read issue #2714 but it's not helping at all.

Expected behavior

contract.events.transfer(
        {
          fromBlock: 0
        },
        (error, event) => {
          if (error) {
            console.error(error);
          } else {
            console.log("successfully");
          }
        }
  );

Executing this code should print the "successfully" message.

Actual behavior

contract.events.transfer is not a function

Steps to reproduce the behavior

Run this code below:

const Web3 = require('web3');
const web3 = new Web3("https://mainnet.infura.io/");
const contractAddress = "0x685bd934b371f2ee4894225064d937a57fb03974";
const minABI = [
    // balanceOf
    {
        "constant":true,
        "inputs":[{"name":"_owner","type":"address"}],
        "name":"balanceOf",
        "outputs":[{"name":"balance","type":"uint256"}],
        "type":"function"
    },
    // decimals
    {
        "constant":true,
        "inputs":[],
        "name":"decimals",
        "outputs":[{"name":"","type":"uint8"}],
        "type":"function"
    },
    // transfer
    {
        "constant":true,
        "inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],
        "name":"transfer",
        "outputs":[{"name":"","type":"bool"}],
        "type":"function"
    }
];
const contract = new web3.eth.Contract(minABI, contractAddress);
contract.events.transfer(
        {
          fromBlock: 0
        },
        (error, event) => {
          if (error) {
            console.error(error);
          } else {
            console.log("successfully");
          }
        });

Error Logs

TypeError: contract.events.transfer is not a function

Versions

  • web3.js: 1.0.0-beta.55
  • nodejs: v10.16.0
  • ethereum node: infura
@taducquang taducquang changed the title events.myevent events.myevent is not working Jul 18, 2019
@nivida
Copy link
Contributor

nivida commented Jul 18, 2019

The added ABI does not contain the event you are trying to listen for. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants