How to Use the Nois Beacon to Get Randomness for Your Application in CosmWasm
Learn how to use Nois to get randomness for your dapp!
Did you ever want to build something in CosmWasm that required a source of randomness?
Well now it is possible thanks to Nois! It provides a source of verifiable, secure and unbiased randomness via IBC. Let’s dive deep 😎.
What is Nois and how does it work?
Nois is a source of reliable randomness for the interchain. It provides a decentralized solution based on Drand that ensures a fair outcome. Think of it as an oracle for providing randomness.
They have made it extremely easy to work with, as you only need to implement two handlers in your application, GetNextRandomness
and NoisReceive.
There is a nois proxy contract containing all the IBC implementation with the nois chain so you don’t have to worry about that.
If your dapp requires randomness, just call the nois proxy contract in the host chain with the GetNextRandomness(job_id)
message. The proxy will do the necessary IBC transactions to fetch the randomness from the nois chain for you, and reply to your contract via the callback NoisReceive { callback: NoisCallback }
. You can see the workflow in detail below, as you can see it’s very straightforward.
What’s on the Nois toolbox?
A series of methods to derive integers, decimals and binary values from a source of randomness:
The toolbox is available both in rust and javascript.
What can you use randomness for?
There are many use cases, the limit is your imagination! Here are some of the things I came up with:
Decentralized Lottery
Randomized Asset Distribution
Gaming Applications
Randomized Auctions
Randomized Prize Distribution in Tournaments
NFT generation
Voting systems
Resources
Your take
What would you use randomness for? Are there any use cases that got unlock thanks to this piece of infra? Let me know in the comments!
If you like this content, please subscribe and share it with other devs that might find it helpful. Also make sure to follow me on X at @jvr0x for time-sensitive Cosmos updates.
Happy coding!
P.S.
Here is a review Katarina from NoisRNG did on my tutorial. Worth reading if you follow this tutorial as it contains key information on how to improve the smart contract.
https://twitter.com/kais_kat/status/1686446290681348109