random with 0x44 OPCODE
Introduction
Solidity is not capable of creating random numbers. Don’t generate random numbers inside your contracts. It won’t work, you will get hacked. Create your own’s algorithm for random numbers by readings blockchain env as a source of random the random number is 100% predictable and blockchain env can be manipulated
Ethereum transition from Proof of Work to Proof of Stake consensus applications may benefit from using the randomness accumulated by the beacon chain. Thus, randomness outputs produced by the beacon chain should be accessible in the EVM.
Example Code
It’s time for the testing
You can get a testing native token for paying the gas fee on https://faucet-sepolia.rockx.com/ and Sepolia RPC Endpoint
- Testing with Remix IDE
- Testing with Ethers.js
from the result above on block.difficulty
always returned zero but the result from a smart contract that calls opcode 0x44
which is RANDOM after network transition from Proof of Work to Proof of Stake consensus algorithm
Conclusion
- Security considerations randomness that’s provided is not 100% safe
inputs that influence the randomness may be predictable and possible to be done in the centralized network - Efficiency and convenience to create simply randomness for digital art or other use cases that not concern too much about the security side
Reading Further
Contents distributed by Learn.Block6.tech
👉 Discord — Live Talks
👉 Twitter — Latest articles