Exploring Randomization Algorithms for WAX Blockchain

bountyblok
5 min readAug 29, 2024

--

Photo by Julia Morales on Unsplash

In the world of blockchain, randomness plays a crucial role in various applications, from drawing winners in a contest to ensuring fairness in game mechanics. When it comes to implementing randomization on the WAX blockchain, there are several algorithms and approaches you can consider. In this article, we’ll dive into three popular methods: using Random.org, Chainlink VRF v2, and the WAX RNG smart contract. Each method offers unique benefits and can be used depending on your specific needs and use cases.

At Bountyblok.io, we leverage all of these methods in our contest giveaway platforms to ensure that every draw is fair, transparent, and secure. By utilizing these diverse approaches, we can tailor the randomization process to fit the specific requirements of each contest, providing the best possible experience for our users.

1. Random.org: External Randomization Service

Overview

Random.org is a well-known service that generates true random numbers from atmospheric noise. It’s particularly useful when you need a reliable and straightforward source of randomness. One of its main advantages is that it’s a widely recognized standard and requires minimal code to implement. However, it is important to note that Random.org is a centralized service, which means that it introduces an external dependency, unlike fully decentralized on-chain solutions. Despite this, its simplicity and reputation make it a valuable tool in scenarios where ease of integration and quick setup are priorities.

How It Works

To use Random.org within your WAX blockchain application, you can make an HTTP request to their API. Below is a sample code snippet demonstrating how to fetch a sequence of random numbers.

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});

xhr.open("GET", "https://www.random.org/sequences/?min=0&max=10&col=1&format=plain&rnd=id.325893200");

xhr.send();

Parameters:

  • Min: Minimum value in the generated random number series.
  • Max: Maximum value in the generated random number series.
  • Rnd: Randomization seed used by Random.org.

More details: https://www.random.org/clients/http/api/

Use Cases

Random.org is ideal for applications where you need an external and independent source of randomness. This method is particularly useful for contests, lotteries, and any scenario where transparency and trust in the random number generation process are paramount.

2. Chainlink VRF v2: On-Chain Verifiable Randomness

Overview

Chainlink VRF (Verifiable Random Function) v2 is a secure and verifiable source of randomness that is generated on-chain. It provides cryptographic proof that the randomness is fair and unbiased, which can be independently verified.

How It Works

To use Chainlink VRF v2, you first need to set up a subscription and deploy a smart contract that interacts with the Chainlink VRF. Here’s how you can request random numbers using web3.js:

var Contract = require('web3-eth-contract');
var contract = new Contract(contractABIJson, "Your smart Contract Address");
contract.methods.requestRandomWords(_count, _maxValue, _callbackGasLimit ).send({from: ....})
.on('receipt', function(){
...
});

Parameters:

  • _count: Number of random numbers requested in a single transaction.
  • _maxValue: The upper limit for the generated random numbers.
  • _callbackGasLimit: Maximum gas limit for the callback function.

Setup your chainlink vrf v2 subscription and smart contract by following the steps here:

https://docs.chain.link/vrf/v2/subscription

https://docs.chain.link/vrf/v2/best-practices

Reading the Random Numbers

Once generated, you can read the random numbers as follows:

var Contract = require('web3-eth-contract');
var contract = new Contract(contractABIJson, "Your smart Contract Address");
var randomNumbers = contract.functions.viewRandomWords().call();

Use Cases

Chainlink VRF v2 is perfect for decentralized applications (dApps) that require on-chain randomness with provable fairness, such as blockchain-based games, NFT minting, and decentralized lotteries.

Considerations

Chainlink VRF v2 is a powerful tool, but it requires careful management of gas fees and contract interactions. Additionally, since the randomness is on-chain, it may be more suitable for applications where the smart contract logic is tightly coupled with the randomization process.

3. WAX RNG: Native Blockchain Randomization

Overview

The WAX RNG (Random Number Generator) is a native solution specifically designed for the WAX blockchain. This method allows you to generate random numbers directly within your WAX-based smart contracts, ensuring seamless integration with your blockchain dApps.

How It Works

You can create and deploy a WAX RNG smart contract by following the tutorial provided in the WAX developer documentation. Once deployed, you can use the waxjs library to call the smart contract function and generate a random number.

const result = await wax.api.transact(
{
actions: [
{
account: "mywaxrngtest", // your smart contract name
name: "getrnd",
authorization: [
{
actor: wax.userAccount,
permission: "active",
},
],
data: {
customer_id: wax.userAccount,
},
},
],
},
{
blocksBehind: 3,
expireSeconds: 1200,
}
);

Reading the Random Number

The generated random number is stored in the rngcustomers table of the smart contract. You can retrieve it using the following command:

cleos -u [chain-api-url] get table mywaxrngtest mywaxrngtest rngcustomers

Use Cases

WAX RNG is ideal for applications native to the WAX blockchain, such as WAX-based games, giveaways, and any other dApp that requires on-chain random number generation. This method provides a streamlined approach without needing external dependencies.

Considerations

While WAX RNG is convenient and efficient for WAX dApps, its randomness is generated within the blockchain environment, which may not be as robust against certain types of manipulation as external sources like Chainlink VRF.

Conclusion

When choosing a randomization algorithm for your WAX blockchain application, it’s important to consider the specific requirements of your use case. Each of the three methods we discussed — Random.org, Chainlink VRF v2, and the WAX RNG smart contract — offers distinct advantages.

  • Random.org provides a straightforward and trusted source of randomness, making it an excellent choice for those who prioritize ease of integration and need a quick, reliable solution. However, as a centralized service, it introduces an external dependency that might not align with the fully decentralized nature of blockchain.
  • Chainlink VRF v2 stands out with its on-chain, verifiable randomness that comes with cryptographic proof, ensuring fairness and transparency. This method is ideal for decentralized applications where on-chain verification is critical, such as blockchain-based games, NFT minting, and lotteries.
  • WAX RNG is a native solution designed specifically for the WAX blockchain. It offers a decentralized approach where the randomness is generated by the WAX RNG smart contract and secured by the WAX RNG Oracle Service. This service, managed by the oracle.wax account, ensures that the random numbers are provably fair by generating RSA signatures. This method seamlessly integrates with WAX dApps, providing a robust and secure randomization mechanism directly within the WAX ecosystem.

At bountyblok, we leverage all these methods in our contest giveaway platforms to ensure that every draw is fair, transparent, and secure. By utilizing a combination of these randomization techniques, we can cater to the specific needs of each contest, offering our users the best possible experience. Whether you need a quick, reliable service like Random.org, the cryptographic security of Chainlink VRF, or the native integration of WAX RNG, there’s a solution that fits your needs.

To find out how you can easily and quickly incorporate bountyblok into your project, we’d love to hear from you:

Website | Telegram | Twitter | Email

--

--