
Getting Started with QRNG
The qrng-example➚ 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 quantum random number.
- qrng-example/contracts/➚
QrngExamples.sol
: A sample requester used to call the QRNG service.
- qrng-example/deploy/➚
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.
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➚ 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 Using QRNG - Remix Example guide.
Designated Sponsor Wallets
Sponsors should not fund a sponsorWallet
with more than 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.
Withdrawals
In the QRNG example project, the requester contract was written with the scope of demonstrating on-chain requests for random numbers.
WARNING
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 sponsorWallet
to sponsor
. Since the requester contract is set as the sponsor➚, the requester contract needs to make the withdrawal request by calling requestWithdrawal
from the WithdrawalUtilsV0➚ contract. The 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.