WHAT THE HACK ARE EVENTS
• Events are a mechanism which let the world know about the state change
happening with in a blockchain.
• This information plays an important role for processing further steps in process .i.e. information update on a dApp or execute next step in business process
• Log entries represent the result of events having fired from a smart contract.
HOW TO GET THE FISH OUT
• Any receivers which are interested on events from a smart contract can listen the Ethereum node over JSON-
RPC OR WS
• This can be either a locally hosted node or can utilized a public hosted node like INFURA.
Ex:
/** HTTP provider using Infura**/
const provider = 'https://mainnet.infura.io/v3/<API - Key>'
const web3 = new Web3(new Web3.providers.HttpProvider(provider));
/** Websocket provider using Infura**/
const provider = 'wss://mainnet.infura.io/ws';
const web3 = await new Web3(new Web3.providers.WebsocketProvider(provider));
• One who has missed the train to capture the real time event logs can also get the fish out using reading the past event logs using web3js methos getPastEvents
Example : myContract.getPastEvents(event[, options][, callback])
Code Sample is reading event bidRevealed from ENS smart contract hosted on ethereum blockchain
Sample code Repo
https://github.com/devrajsinghrawat/Web3nSolidity/tree/master/eventScan