4

I read the following in Andreas Olofsson's answer:

Events can also be filtered by the hash of the transaction that generated the event

Would someone please post an example of how to do this with oo7-parity.js, web3.js or ethjs ...

I've not found any particularly helpful examples in the the docs

q9f
  • 32,913
  • 47
  • 156
  • 395
matthew
  • 579
  • 7
  • 14
  • Does anyone know if this is possible with the ethers.js library? Their docs show event handling in their Low-level API (https://docs.ethers.io/ethers.js/api-advanced.html#low-level-api), but it's not clear if it's possible to specify a contract to watch. – matthew May 18 '17 at 19:40

1 Answers1

4

So this can be done by watching for contract events, optionally from a specified sender, and then filtering the result by the transaction hash. Here's an example using web3.js:

const Web3 = require('web3');
const web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://127.0.0.1:8545'));

const multiSigWalletFactoryAddress = '0xF935...c5B9F1f';
const MultiSigWalletFactoryABI = [{"constant":true,"...","type":"event"}];
const MultiSigWalletFactory = web3.eth.contract(MultiSigWalletFactoryABI);
const multiSigWalletFactoryInstance = MultiSigWalletFactory.at(multiSigWalletFactoryAddress);

const event = multiSigWalletFactoryInstance.ContractInstantiation({sender: '0x72D0...ef412F'});

event.watch(function(error, result) {
  if (error) {
    console.log('error', error);
  } else {
    // here the transaction hash can be checked and filtered on
    console.log('result.transactionHash', result.transactionHash);
    // here the arguments from the Event can be read
    console.log('result.args', result.args);
  }
});

Docs: web3.eth.filter, contract-events

To help others that might stumble over the same gotcha, one reason I was struggling with getting this to work was because I was testing https://kovan.infura.io/ and didn't realise that eth_newfilter is not one of their supported json rpc methods

matthew
  • 579
  • 7
  • 14