0

I'm writing a fun game as a solidity contract and looking to generate somewhat random (or unpredictable numbers). I have researched this topic and am aware using an off chain oracle is the best practice for this. In my particular use case using an oracle such as chainlink will incur too much cost. Similarly using an approach that spans more than a single transaction might be more effort than it is worth (forcing the user to both do a play and possibly claim tx). Assuming there will be none or very little monetary reward for playing the game would the following approach be suitable.

Use block hash of previous block along with numerous other sources of numbers such as timestamp, balance of popular uniswap pairs, lending pools balance, weth total supply etc, essentially sourcing entropy from on chain sources.

I intend to only allow transactions from EOAs not contracts. My thinking is that in order for a user to guess what the random variable would be they would need to know the state of all the inputs and submit their tx before these change. I also intend to deploy on a chain that has a shorter blocktime than ethereum and generally produces a block every two seconds.

Is there much risk to my approach or anything I haven't considered?

1 Answer 1

1

Have you considered using block.prevrandao?

Read these pointers to see if it makes sense for you and to make sure you're using it properly, but for a game with little to no monetary reward this could be appropriate:

https://eips.ethereum.org/EIPS/eip-4399

https://soliditydeveloper.com/prevrandao

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.