3

I need to watch events by two parameters: address of token contract and sender address. I found how to watch contract address, but not sure how to watch also by sender address? Shoud I specify address to topics like this?:

var eventFilter = web3.eth.filter({
    fromBlock:0,
    toBlock: 'latest',
    address: '0xefcc9f9a5cb3d6062c18eeffdf90a29bb771fccc',
    'topics':[web3.sha3('Transfer(address,address,uint256,uint256)'), web3.sha3('0xdd7b798cbfe06af77fdc4b64e48f71672595adcf')]});
eventFilter.watch(function(error, result) {
    if(error) throw error;
    console.log(result);
});

or maybe there is a different way?

1

The address in the FilterChange is the emitting contracts address.

You need to include the sender address in your event definition in order to get in FiltecChange. Only if you index the address it will show up in topics, so that you can filter for it.

event CalledTrigger (address indexed from, uint256 value1, uint256 value2);

function triggerEvent() public {
  uint256 myVal1 = 9999;
  uint256 myVal2 = 9999;
  emit CalledTrigger2(msg.sender, myVal1, myVal2);
}

But your problem might be that your topic[1] is the sha3 of an address, not the address I guess you want to filter for.

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.