[Ethereum] How to get a pending filter only for a contract

go-ethereumweb3js

I would like to do the equivalent of:

pendingEvent = web3.eth.filter('pending');

but only for a specific contract:

pendingContractEvent = myContractInstance.allEvents('pending');

or more specifically:

pendingContractEvent = myContractInstance.myEvent('pending');

When I do this, I get the event only when the transaction is included in a block (like 'latest').

Best Answer

I would like to do the equivalent of:

pendingEvent = web3.eth.filter('pending');

Yes you can do using web3.eth.filter with options. By specifying address in options you can do archive your problem. I am just attaching sample code for ref.

var options = {address: <CONTRACTADDRESS>};
var filter = web3.eth.filter('pending', options);

filter.watch('pending',function (error, log) {
     console.log(log);
  }
});

Click below link for more details.

https://github.com/ethereum/wiki/wiki/JavaScript-API