1 min readFeb 1, 2019
Hi Hani,
The game was made for browser using Web3.js, so to access the event logs you just call getPastEvents
on your contract instance.
A tip for saving on load time is to use the block you deployed your contract as the fromBlock
value. Something else I wish I’d done is record the block number when situations are submitted and use that as fromBlock
depending on the situation, because as is, the load time is going to continue to grow the longer the Ethereum main chain gets.
Actual code from the game is below:
const situation = await instance.getPastEvents("Situation", {
filter: {id: [id_of_situation]},
fromBlock: 7073631,
toBlock: 'latest'
}).then(events => {
//Do stuff with the event
You can find that on line 11392 of this file on GitHub.
Cheers,
Andrew