Solidity Events not always firing on Sokol

#1

Hello! I make small dApp games on Ethereum. Having heard about POA for a while, I decided to take the plunge and ported one of my games to Sokol.

As I am a beginner to programming in general, I was expecting the process to be arduous. It was a pleasant surprise to see how easy you guys make it. It’s as close to a straight clone as it can get!

However, I’m running into a problem on Sokol: when I try to subscribe to events on my frontend using web3.js and “watch”, sometimes the events register, sometimes they don’t.

The very same code works flawlessly on Ethereum, both Mainnet and Ropsten; and so I’m curious if there’s a particularity to Sokol/POA regarding events I’m missing.

Querying past events with “get” works just fine, so in the meantime I’ve resorted to querying all events every minute and updating the start block of that query to the end block of the latest event. It’s an acceptable solution for my usecase, even if it implies a one minute lag before the event log registers actions.

Again, I’m very much a newbie to programming so if there’s some other information I need to provide, let me know. I’m not asking for handholding, just curious if there’s any different specification between Ethereum and POA I should be aware of.

I’m loving the POA project so far, and can’t wait to experiment with xDai too. Cheers. :slight_smile:

0 Likes

#2

Hi,

Do you use MetaMask or Nifty wallet extensions to generate transactions in the dapp?

As far as I know, MetaMask has an issue with a double firing of events, if you have multiple watchers of separate events in the Dapp, and we fixed it in Nifty wallet. But, maybe, this is not is your case. If that is not the case, is it possible to look through the code of the game (front, smart-contracts)? maybe, you could provide links to GitHub?

1 Like

#3

Hey,

please try to use a direct URL to a node and let us know if it works for you

Archive Fullnode Endpoint (can be useful to setup BlockScout for Sokol)
http://3.85.253.242:8545

WebSockets Endpoint (can be useful to setup BlockScout for Sokol)
ws://3.85.253.242:8546

Cheers

1 Like

#4

Wow, that is really good information Viktor, thank you!

I’m using MetaMask to generate transactions, as do most desktop players, and MM usage is so ubiquitous I assumed the double firing of events was a web3 thing. I’m handling it by storing each event transaction hash and checking it isn’t already there before showing the event.

The strange part is, I’m doing this for both the getPastEvents that works 100% fine on Sokol, and the watch events that work haphazardly. And on Ethereum mainnet as on Ropsten, both types of event watching methods work 100% fine.

Perhaps I should get my userbase to switch to Nifty Wallet… Easier said than done. :slight_smile:

My frontend is at https://github.com/snailking/poa_snailfarm, the relevant code in poasnailfarm.js (jumbled mess, but line 2931 and beyond are all event related).
The smart contract is verified at https://blockscout.com/poa/sokol/address/0xa1c8cc49f38d0546da099f4249f0756baab4646d/contracts

Igor, I will test this direct URL in the future. I’m running into difficulties for troubleshooting today, because the event watching is working today (without me changing anything). It would be easier if I could get it to reliably fail. :smiley:

Thanks for your help!

2 Likes