Testing on-chain RNG.
Ethereum PoS introduces randomness using block.difficulty
. Please check EIP-4399 to learn more about this. I got some inspiration there.
The getRandom()
function will return a random number between 1 and 100.
Can't use it on Optimism (docs).
npm i
npx hardhat test
Create a .env
file with the following variables:
GOERLI_URL=88888
PRIVATE_KEY_GOERLI=88888
Add your own RPC endpoint and private key.
Deploy to Goerli:
npx hardhat run scripts/deploy.ts --network goerli
Then, get your random number:
npx hardhat run scripts/getRandom.ts --network goerli
Feel free to contact me via Element, Telegram, Twitter, Discord, or LinkedIn.