0

I'm wrote this sample but I want to filter specific events 'unsealBid' and list events of the past (e.g. the last 1 or 2 days).

const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/65386ae7c95b446c889a41405aec48e1');

const abi = [{ "constant": false, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "releaseDeed", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "getAllowedTime", "outputs": [{ "name": "timestamp", "type": "uint256" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "unhashedName", "type": "string" }], "name": "invalidateName", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "name": "hash", "type": "bytes32" }, { "name": "owner", "type": "address" }, { "name": "value", "type": "uint256" }, { "name": "salt", "type": "bytes32" }], "name": "shaBid", "outputs": [{ "name": "sealedBid", "type": "bytes32" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "bidder", "type": "address" }, { "name": "seal", "type": "bytes32" }], "name": "cancelBid", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "entries", "outputs": [{ "name": "", "type": "uint8" }, { "name": "", "type": "address" }, { "name": "", "type": "uint256" }, { "name": "", "type": "uint256" }, { "name": "", "type": "uint256" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "ens", "outputs": [{ "name": "", "type": "address" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "_hash", "type": "bytes32" }, { "name": "_value", "type": "uint256" }, { "name": "_salt", "type": "bytes32" }], "name": "unsealBid", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "transferRegistrars", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "name": "", "type": "address" }, { "name": "", "type": "bytes32" }], "name": "sealedBids", "outputs": [{ "name": "", "type": "address" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "state", "outputs": [{ "name": "", "type": "uint8" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "_hash", "type": "bytes32" }, { "name": "newOwner", "type": "address" }], "name": "transfer", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "name": "_hash", "type": "bytes32" }, { "name": "_timestamp", "type": "uint256" }], "name": "isAllowed", "outputs": [{ "name": "allowed", "type": "bool" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "finalizeAuction", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "registryStarted", "outputs": [{ "name": "", "type": "uint256" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "launchLength", "outputs": [{ "name": "", "type": "uint32" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "sealedBid", "type": "bytes32" }], "name": "newBid", "outputs": [], "payable": true, "type": "function" }, { "constant": false, "inputs": [{ "name": "labels", "type": "bytes32[]" }], "name": "eraseNode", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "_hashes", "type": "bytes32[]" }], "name": "startAuctions", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "hash", "type": "bytes32" }, { "name": "deed", "type": "address" }, { "name": "registrationDate", "type": "uint256" }], "name": "acceptRegistrarTransfer", "outputs": [], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "_hash", "type": "bytes32" }], "name": "startAuction", "outputs": [], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "rootNode", "outputs": [{ "name": "", "type": "bytes32" }], "payable": false, "type": "function" }, { "constant": false, "inputs": [{ "name": "hashes", "type": "bytes32[]" }, { "name": "sealedBid", "type": "bytes32" }], "name": "startAuctionsAndBid", "outputs": [], "payable": true, "type": "function" }, { "inputs": [{ "name": "_ens", "type": "address" }, { "name": "_rootNode", "type": "bytes32" }, { "name": "_startDate", "type": "uint256" }], "payable": false, "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "hash", "type": "bytes32" }, { "indexed": false, "name": "registrationDate", "type": "uint256" }], "name": "AuctionStarted", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "hash", "type": "bytes32" }, { "indexed": true, "name": "bidder", "type": "address" }, { "indexed": false, "name": "deposit", "type": "uint256" }], "name": "NewBid", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "hash", "type": "bytes32" }, { "indexed": true, "name": "owner", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }, { "indexed": false, "name": "status", "type": "uint8" }], "name": "BidRevealed", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "hash", "type": "bytes32" }, { "indexed": true, "name": "owner", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" }, { "indexed": false, "name": "registrationDate", "type": "uint256" }], "name": "HashRegistered", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "hash", "type": "bytes32" }, { "indexed": false, "name": "value", "type": "uint256" }], "name": "HashReleased", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "name": "hash", "type": "bytes32" }, { "indexed": true, "name": "name", "type": "string" }, { "indexed": false, "name": "value", "type": "uint256" }, { "indexed": false, "name": "registrationDate", "type": "uint256" }], "name": "HashInvalidated", "type": "event" }];
const address = '0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef';

const contact = new web3.eth.Contract(abi, address);


contact.getPastEvents('AllEvents', 
    {
        //filter: {myIndexedParam: [1,44], myOtherIndexedParam: '0x47872b42'}, // Using an array means OR: e.g. 20 or 23
        fromBlock: 6614389   ,
        //fromBlock: web3.eth.getBlockNumber('latest') - (60 * 60 * 24 * 7) / 14,
        toBlock: 'latest'
    }, (err, events) => {
        console.log(events);
    })
0

You can do:

contact.BidRevealed({fromBlock: 6614389, toBlock: 'latest' }).get(function(err, logs){console.log(logs)}
6
  • What is the account {'from': account}?
    – ahmed
    Oct 31 '18 at 12:00
  • Sorry that was a mistake I fix it. btw there is no event called unsealBid in that contract, there is a function called unsealBid
    – Jaime
    Oct 31 '18 at 12:07
  • ` contact."unsealBid"({fromBlock: 6614389, toBlock: 'latest' }). get(function(err, logs){console.log(logs)});` ?
    – ahmed
    Oct 31 '18 at 12:12
  • ahmed, unsealBid is not an event, is a function, thats why you do not see events for unsealBid
    – Jaime
    Oct 31 '18 at 13:00
  • this is my task :r list or visualize the ENS contract events of the past (e.g. the last 1 or 2 days). focussing in particular on the bid revelation event: unsealBid(bytes32 _hash, uint256 _value, bytes32 _salt)
    – ahmed
    Oct 31 '18 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.