Admin account triggering multiple transactions for P2E game

I just watched Build a Play2Earn game tutorial on youtube.

So whenever the game is done and player won, playerWon() from smart contract is called by moralis cloud which uses admin private key.

Question here is, what if 1k or 10k people played the game and won simultaneously or between the similar time? I know it’d be hectic for one admin account to process tons of transactions at the same time because of the nonce issue.

What’s the production level solution to this?

You can make transactions simultaneously (libraries like ethers.js or web3.js have tools for managing the nonce in these situations e.g. when users have wanted to make say 2-5 transactions together), but for something like a theoretical 1000 transactions at the same time, some sort of queuing system would probably make sense to process them in batches.

1 Like

yeah, i’ve already used web3.js to make multiple transactions simultaneously by adding different nonces manually using web3.eth.getTransactionCount(accountAddress, 'pending'), but like in this thread I’ve also encountered some errors as well -probably out of sync.

Also, for ethers.js and based on this thread I think sending many transactions (like 1k) at the same time may not be done smoothly.

So queuing system makes more sense to me, but what’s your approach to send them in batches?

probably you can try to send only a limited number of transactions at a time, for example 10 at once, and then read 10 more transactions from the queue

depending on your smart contract, maybe you could implement a smart contract function that accepts a list of wallets and values

maybe you could implement a smart contract function that accepts a list of wallets and values

alright, so i think what i can do is:

  • playerWon() method has onlyAdmin modifier
  • set 5 wallets to have an admin role
  • add enough MATIC per each account to process tx (or i can use a meta-tx relayer like biconomy to manage this in one gas tank)
  • admin wallet #1 processes 10 transactions in batch first
  • at the same time, process another 10 transactions using admin wallet #2
  • admin wallet #3, #4, etc goes on if there are more transactions

I think this is the way to go to process and run in parallel as much as possible?

That is probably a good solution to use multiple wallets like that - and if one fails e.g. runs out of currency for whatever reason, another one can be used. You will need to do a lot of testing.

1 Like