# QRNG Example Project
The qrng-example (opens new window) project (GitHub repo) demonstrates how to build a smart contract (known as a requester) using the Airnode request–response protocol to receive QRNG services. It is recommended to run the example project to learn how it uses the QRNG service on a testnet, and read the associated README file. It also contains example code that will be useful when creating a requester (smart contract) that requests a random number.
- qrng-example/contracts/ (opens new window)
QrngExamples.sol: A sample requester used to call the QRNG service.
- qrng-example/deploy/ (opens new window)
deploy.js: Script that deploys a requester to a chain.
setup.js: Script that sets the parameters on the requester contract. These parameters are used when calling the QRNG service.
fund.js: Script that funds the wallet the requester uses to pay the gas costs.
Using the QRNG service is free, meaning there is no subscription fee to pay. There is a gas cost incurred on-chain when Airnode places the random number on-chain in response to a request, which the requester needs to pay for.
# Sponsor Wallet
The QRNG example project sets the sponsor wallet (opens new window) using the requester address. The wallet is then used to pay gas costs when the Airnode responds to a request. An alternate method is to use the Admin CLI as is the case with the Remix Example Project.
Designated Sponsor Wallets
Sponsors should not fund a
sponsorWallet with more then they
can trust the Airnode with, as the Airnode controls the private key to the
sponsorWallet. The deployer of such Airnode undertakes no
custody obligations, and the risk of loss or misuse of any excess funds
sent to the
sponsorWallet remains with the sponsor.
In this example, the requester contract was written with the scope of demonstrating on-chain requests for random numbers.
For brevity, the requester contract does not contain withdrawal or other additional functionality.
For those inclined, withdrawal functionality can be added to the requester
contract. First, funds must be transferred from
Since the requester contract is
set as the sponsor (opens new window),
the requester contract needs to make the withdrawal request by calling
requestWithdrawal from the
WithdrawalUtilsV0 (opens new window)
AirnodeRrpV0 contract inherits this contract and therefore the
published addresses can be
used. Second, a withdrawal function must be added to the requester contract such
that the owner of the requester contract can transfer the requester contract
balance to their address.