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

[SOLVED] events.MyEvent broken since .52 #2714

Closed
Mozeps opened this issue Apr 20, 2019 · 4 comments
Closed

[SOLVED] events.MyEvent broken since .52 #2714

Mozeps opened this issue Apr 20, 2019 · 4 comments
Labels
Needs Clarification Requires additional input

Comments

@Mozeps
Copy link

Mozeps commented Apr 20, 2019

Description

Subscribing to an event of a contract deployed to a ganache blockchain-client using events.EventName or events[eventSignature] throws an error. The syntax follows the example of the web3 docs (https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id38).

Expected behavior

myContract.events.SomethingHappened(
        {
          fromBlock: 0
        },
        (error, event) => {
          if (error) {
            console.error("subscription error:", error);
          } else {
            console.log("successfully caught event");
          }
        }
  );

Executing this code should print the "successfully caught event" message multiple times to the console.

Actual behavior

Following error message is printed:
myContract.events.SomethingHappened is not a function

If I use events.AllEvents the command works as expected.

Steps to reproduce the behavior

  1. Run Ganache
  2. Deploy a contract similar to the following:
pragma solidity ^0.5.0;

contract SubContract1 {

  bytes32 public state;

  event SomethingHappened(
    bytes32 name
  );

  constructor() public {
      state = stateOne;
  }

  bytes32 stateOne = "state one";
  bytes32 stateTwo = "state two";
  bytes32 finishedText = "Finished doing something";

  function doSomething() public {
    if(state == stateOne) {
        state = stateTwo;
    } else {
        state = stateOne;
    }
    emit SomethingHappened(finishedText);
  }
}
  1. Initialize web3 in Node.js like so:
    let web3 = new Web3.providers.WebsocketProvider("ws://localhost:8545");
  2. Initialize the contract in Node.js like so:
    let myContract = new web3.eth.Contract(abi, address);
  3. Run subscription code shown in the beginning.

Error Logs

(node:23124) TypeError: myContract.events.SomethingHappened is not a function

Versions

  • web3.js: 1.0.0-beta.52
  • nodejs: v10.15.0
  • ganache: v2.0.0
@nivida
Copy link
Contributor

nivida commented Apr 23, 2019

Thanks for opening this issue!
Could you add the ABI you are using?

@Mozeps
Copy link
Author

Mozeps commented Apr 24, 2019

[ { "constant": true, "inputs": [], "name": "state", "outputs": [ { "name": "", "type": "bytes32" } ], "payable": false, "stateMutability": "view", "type": "function", "signature": "0xc19d93fb" }, { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor", "signature": "constructor" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "name", "type": "bytes32" } ], "name": "SomethingHappened", "type": "event", "signature": "0x131651a9ef17e0a6963ff90cb2e0d1007110861a27cec93815590ae0bb418e69" }, { "constant": false, "inputs": [], "name": "doSomething", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function", "signature": "0x82692679" } ]

@nivida
Copy link
Contributor

nivida commented Apr 25, 2019

Thanks, I'll test it asap.

@nivida nivida added Needs Clarification Requires additional input and removed more information needed labels Apr 25, 2019
@Mozeps
Copy link
Author

Mozeps commented May 11, 2019

Requesting to close this issue.

After updating ganache to v.2.1 I cannot replicate this issue.

@Mozeps Mozeps changed the title events.MyEvent broken since .52 [SOLVED] events.MyEvent broken since .52 May 13, 2019
@nivida nivida closed this as completed May 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Clarification Requires additional input
Projects
None yet
Development

No branches or pull requests

2 participants