Secret VRF for IBC with IBC-Hooks
Verifiable on-chain random number generator for the entire Cosmos.
Last updated
Verifiable on-chain random number generator for the entire Cosmos.
Last updated
This VRF tutorial uses IBC Hooks, as introduced in IBC v3.4.0. If your chain is on a previous IBC version, see the SecretVRF tutorial using proxy contracts here.
Secret VRF is a provably fair and verifiable on-chain random number generator (RNG) that enables smart contracts to access random values without compromising security or usability. Coupled with cross-chain interoperable smart contracts using IBC hooks, Secret Network enables developers and projects across the Cosmos access to state-of-the-art on-chain RNG.
Use Secret VRF to build reliable smart contracts for any application that relies on unpredictable outcomes:
NFT Minting: Utilize randomness for features like unordered minting, trait randomization, and identity numbering, enhancing the authenticity and security of NFT collections.
Web3 Gaming: Apply randomness in gambling, damage calculation, loot boxes, and boss drops to build trust among players by ensuring fairness and preventing any player from having an unfair advantage.
DAO Operations: Employ randomness for wallet initialization, task assigning, unordered voting/liquidations, and order book ordering, facilitating equitable and secure decentralized governance and operations.
Learn more about how SecretVRF works in-depth here.
To use SecretVRF on any IBC-enabled chain with IBC hooks, all that is required is:
An IBC transfer channel between Secret Network and the consumer chain that receives randomness.
Uploading the RNG Consumer Contract to your chain and directing it to your chain's transfer channel
Git clone
the IBC hooks randomness repository:
Update the SECRET_TRANSFER_CHANNEL_ID
and the CHAIN_TRANSFER_CHANNEL_ID
to the channel-id for your IBC-enabled chain:
For this example, we request randomness on Juno Mainnet, but you can request randomness on any IBC-compatible chain that has a transfer channel established with Secret Network.
Once you have updated the transfer channels, compile the contract:
Upload the compiled contract:
Upon successful upload, a code_id
is returned:
Instantiate the contract with the returned code_id
:
Upon succesful instantiation, a contract_address
is returned:
Now that you've instantiated your randomness contract, all that's left is to request randomness! Simply execute request_random:
A transaction hash will be returned:
You can update the job_id
string to any string of your choosing
Navigate to the recently received transactions for your contract:
And then view the magic of cross-chain randomness with IBC hooks 😍:
Congrats! You've just sent a verifiable on-chain random byte
with SecretVRF 🙌.
Secret VRF revolutionizes blockchain applications by providing a secure and verifiable source of randomness, critical for fairness in NFT minting, gaming, and DAO operations. Its seamless integration with IBC hooks enables cross-chain interoperability, allowing developers across the Cosmos ecosystem to build more reliable and elegant smart contracts.
If you have any questions, join our discord and a Secret developer will assist you ASAP.