0

relevant code:

token.getPastEvents('Approval', {
    fromBlock: 0,
    toBlock: 'latest'
}, function (error, events) { console.log("ETHEREUM past events " + JSON.stringify(events)); });

token.events.Approval({
    fromBlock: 0
}, function (error, event) { console.log("NEW ETHEREUM EVENT " + JSON.stringify(event)); })

token.events.allEvents({
        fromBlock: 0
}, function (error, event) { console.log("NEW ETHEREUM EVENT " + JSON.stringify(event)); })

First call works perfectly. The latter two do not.

I've got to be missing something pretty simple/stupid here . . . . but I can't pick it out. :-(

  • If the exact same code works correctly for you on previous versions, then you should probably report that as an issue on their GitHub. – goodvibration Mar 9 at 14:31
0

Wow! I figured it out (and it's a worthwhile thing to know)

contract.events requires a web socket connection & contract.getPastEvents does not

The fix was to change

const web3 = new Web3('http://localhost:8545');

to

const web3 = new Web3('ws://localhost:8545');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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