Ethereum events and reading past events

in #busy5 years ago

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

image.png

Sample code Repo
https://github.com/devrajsinghrawat/Web3nSolidity/tree/master/eventScan

Sort:  

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by DevD from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: 50SP, 100SP, 250SP, 500SP, 1000SP, 5000SP.
Be sure to leave at least 50SP undelegated on your account.

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.033
BTC 64507.66
ETH 3080.07
USDT 1.00
SBD 3.85