This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3'); | |
const web3 = new Web3('// your rpc url here'); | |
// connection to smart contract | |
const address = // your contract string | |
const abi = // your contract abi here | |
const contract = new web3.eth.contract(abi, address); // your contract instance | |
contract.getPastEvents( | |
'AllEvents', // you can send any event name like 'transfer' or something | |
{ | |
fromBlock: 0, | |
toBlock: 'latest', | |
}, // can provide a block range here to filter your events | |
(err, events) => { | |
console.log(events); | |
} | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
here you can see all openzeppelin events ('predefined events') | |
now the events which are consoled have all the events which had occured between block 0 to the very latest block | |
there are other ways to get events such as filtering events | |
contract.getPastEvents( | |
'AllEvents', | |
{ | |
filter: { | |
value: 'name of event' or ['event 1', 'event 2'], | |
date: // can filter by date | |
, | |
(err, events) => { | |
console.log(events); | |
} | |
by this way you can add some more filter to events | |
And last method of getting events i have already explained using event emitters | |
// https://hashnode.com/draft/62556a336386ed96b050c946 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment