1

My Dapp needs to dynamically deploy contracts. As such, I need to store the addresses of these contracts somewhere and opted for the following solution:

  1. Log creation event
  2. Retrieve contracts based on logs

The snippet which performs logging is this one:

event Created(address indexed _who, address indexed _to_whom, uint money, uint _max_duration);

//...

Created(msg.sender, _to_address, money_quantity, _contract_max_duration);

In web3.js I'm having a hard time trying to understand how to filter logs based on: Contract Type, _who parameter and eventually _to_whom parameter.

I'm getting all the logs (in js):

var filter = web3.eth.filter({fromBlock:0, toBlock: 'latest', topics: [/* ????!!! */]});

filter.get(function(error, result) {
   console.log(result)
})

In the console I get the hashes of 3 "topics" which I suggest, by reverse engineering, are the Contract Type hash and the other two indexed event parameters.

Let's say that I want to query for all events of type Contract Type having the current user as _who parameter. How do I do it? What do I insert in the topics argument?

Many thanks

1

From the experience, the issue of using the filter is quite complicated, since the use of callback and synchronization with the blockchain make this type of utilities difficult.

To begin with, I tell you that the ideal would be to filter through the exact block that is the only one that gives me resultant feedback and does not give me failures. The fastest would be to use an external log to save the transactions and addresses.

I also recommend that you see this API, so you know a little how to work with these topics.

Tea I leave a pretty useful link with a case similar to what you try. Link

  • From your experience, is searching only for events from a single contract fast or should I better switch to Etherscan API? Because now I'm thinking about creating these dynamic contracts from one single contract hardcoded in the app. Then searching for the Creation events of that origin contract. Thanks – Federico Capello Jun 6 '17 at 21:51
  • Is fast use Etherscan API, but is a external Api so... i you want create yourself searcher in the blockchain is better use a external log for save the results and then search in this log, because is faster than use a filter. Maybe ina future this filter functiosn are better... – Gawey Jun 7 '17 at 7:14
  • Ok thanks. I'll benchmark these options when I deploy to main net – Federico Capello Jun 7 '17 at 7:15

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.