0

I am trying to do a simple test for events. Following is solidity code.

Values received from chgEvent.watch are always correct.

But in chgEvent.get, results1 is empty. chgEvent.get does not get called at emit of event in contract, also there is no error printed.

I am connecting to Ganache.

Please suggest why chgEvent.get is not firing.

pragma solidity ^0.4.0;

    contract eventTestContract
    {
        uint8 public dummy;
        event eventOnDummy
        (
           uint dumm
        );
        function setDummy(uint8 _dummy) 
        {
           dummy = _dummy;
           eventOnDummy(_dummy);
        }
        function getDummy() returns (uint8)
        {
            return dummy;
        }
    }

Following is web3.js relevant code:

var myInstrContract = InstrContractABI.at('0x12e47158657b7ed4ce241ab29cca76b88aa51aab');
        var chgEvent = myInstrContract.eventOnDummy({},{fromBlock: 0, toBlock: 'latest' });

        chgEvent.get(function (error, results1) {
            if (!error) {
               console.log("value from event.get "+JSON.stringify(results1.args));
            } else {
                console.log(error);
            }
        });

        chgEvent.watch(function (error, results) {
            if (!error) {
               console.log("value from event.watch "+results.args.dumm);
            } else {
                console.log(error);
            }
        });

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

The function event.get() will return a list of existing events. It will not subscribe for new events.

As you already know the function to subscribe to new events is event.watch().

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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