0

I am trying to get all the events that originate from zero (0x0) address in order to capture the mint activity for my ERC20 token.

Here is my code snippet:

var instance = web3.eth.contract(abi).at(tokenContractAddress);
var blockNo = web3.eth.blockNumber;
console.log('latest block', blockNo); //able to get blockNo successfully

var result = instance.Transfer({from: '0x0000000000000000000000000000000000000000'},
            {fromBlock:4361077, toBlock:'latest'}, 
           (err, res) => {
             console.log(res);
        });

However i never get anything in the res object and its always undefined.

0

I believe that you should change this:

{from: '0x0000000000000000000000000000000000000000'},
        {fromBlock:4361077, toBlock:'latest'}

To this:

{from: '0x0000000000000000000000000000000000000000',
        fromBlock:4361077, toBlock:'latest'}

If it's still not working for you, then you can try this:

instance.allEvents().get(function(error, logs) {
    assert(error === null);
    for (let i = 0; i < logs.length; i++) {
        if (logs[i].event == 'Transfer' && logs[i].args.from == '0x0000000000000000000000000000000000000000') {
            console.log(logs[i]);
        }
    }
});
  • i assume you mean logs[i].event == 'Transfer' I tried both and the console statement is never executed – stud91 May 28 at 8:37
  • @stud91: Yes, my mistake with that comma there, changed it to ==. Are you sure that such an event has been fired prior to your attempt? – goodvibration May 28 at 8:42
  • yes, please refer to rinkeby.etherscan.io/address/… – stud91 May 28 at 8:47

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.