1

My approach here was to listen for Transfer event for a contract (e.g. Cryptokitties) filtered by the indexed from account.

var contract = new web3.eth.Contract(kittyABI, kittyContractAddress, 
{from: account});
contract.events.Transfer(
  {filter: {from: account}}, fromBlock: 0},
  function(error, event){ console.log(event); })

The provider was at first Metamask. But that threw the error: The current provider doesn't support subscriptions

So, I switched over to Infura. Infura had a similar problem unless you use websockets. The error went away and instead I started battling with timeout issue. After much effort, it seems like Infura websocket approach is still not perfectly functioning. So, I am thinking of rolling out my own geth node that simply runs that query. But before I do that, is there anything that I am missing? The problem shouldn't be this hard. I have seen a lot of ERC20 wallets afterall.

  • I don't think there's other way than reading events. – Maxpeinas Sep 26 '18 at 4:33
1

A problem with CryptoKitties implementation of ERC721 is that events parameters are not indexed:

event Transfer(address from, address to, uint256 tokenId)
event Approval(address owner, address approved, uint256 tokenId);

This causes filtering to be a more costly operation and to cause timeouts. Since it is part of the contract this cannot be changed and it will affect your own node.

The final standard have them indexed and you wil not have problem with new implementations that follow it.

For CryptoKitties a possible solution is to index all events in a database separately.

  • Oh, awesome. Good to know. I completely missed this. :) – whatever123 Sep 27 '18 at 19:37

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.