Scope in events in web3 1.0

by Alex   Last Updated January 11, 2019 08:28 AM

Inside the callback of an event, how do I get the scope outside the function? Specifically, in the following scenario, I want the web3 object: (using truffle-contracts and web3 1.0 here)

...
const web3 = new Web3(someProvider);

myContract.deployed().then(function(instance) {

        //both ways work
        instance.myEvent({}, function(error, event){

            //here, I want to use web3
            web3.toAscii(event.args[0])
        })
});


Related Questions


Updated April 11, 2018 22:28 PM

Updated October 02, 2017 19:28 PM

Updated July 31, 2017 09:28 AM

Updated February 27, 2018 06:28 AM

Updated April 02, 2018 23:28 PM