Reading Past Events Emitted by a Contract

I run a blockchain-based game in which I would like for players to be able to purchase in-game items with our existing erc-20 token. This is straightforward enough if the user is interacting with my dapp and waits on page for the on('receipt', (receipt) => {}) callback so that I can record their in-game purchase. My question is, how do I account for situations where the player leaves the page before the confirmation is returned?

The only solution I can imagine is to store in my DB the transaction hash of a pending transaction and then run an event every ~X minutes to check for new confirmations that may match those pending transactions. Is there a better / easier way to do this? And if not, how would I query the contract for past events that may match these pending purchases?

1 Like