var options = {
fromBlock: 0,
address: web3.eth.defaultAccount,
topics: ["0x0000000000000000000000000000000000000000000000000000000000000000", null, null]
};
web3.eth.subscribe('logs', options, function (error, result) {
if (!error)
console.log(result);
})
.on("data", function (log) {
console.log(log);
})
.on("changed", function (log) {
});
// Solidity program to demonstrate
// creating an event
pragma solidity ^0.4.21;
// Creating a contract
contract eventExample {
// Declaring state variables
uint256 public value = 0;
// Declaring an event
event Increment(address owner);
// Defining a function for logging event
function getValue(uint _a, uint _b) public {
emit Increment(msg.sender);
value = _a + _b;
}
}
let options = {
filter: {
value: ['1000', '1337'] //Only get events where transfer value was 1000 or 1337
},
fromBlock: 0, //Number || "earliest" || "pending" || "latest"
toBlock: 'latest'
};
myContract.getPastEvents('Transfer', options)
.then(results => console.log(results))
.catch(err => throw err);