Use Solidity Development Tools
A DApp or Web3 game developer can also interact with the Adapter contract directly. While you can do this in many ways, such as via Remix, Etherscan, or programmatically, we recommend using Cast from the Foundry framework.
Prerequisites
Smart Contract development experience in Solidity
Experience with Foundry Solidity development toolkit
Installation
Install Foundry
Steps
The instructions below outline the steps a user needs to take in order to request randomness from ARPA Randcast.
Export your Environment Variables
You can export several environment variables to streamline the execution of the subsequent commands.
Note: the adapter contract address for the chain you are using can be found on the Supported Networks & Parameters.
Create a Subscription
In this step, a subscription is created on the ADAPTER_CONTRACT using the createSubscription
method. Save this subscription ID as it will be used later on. The cast send
command broadcasts a transaction to the Ethereum network.
(Reference: cast send)
Gather Subscription Details
The subscription id can be retrieved from the contract event logs for subsequent steps.
You can provide the block number from Step 2 to speed up the event search.
(Reference: cast logs)
Fund the Subscription
Next, fund your subscription with Ethereum. These funds will be used to pay for your subsequent randomness requests.
Note: Recommended eth amounts:
OP Goerli / Mainnet: 0.01 ETH
Sepolia: 0.1 ETH
If needed, you can use the Randcast CLI dryrun to estimate how much ETH each randomness request will cost.
Deploy the Consumer Contract
The user needs to deploy a contract that will consume the randomness provided by Randcast. "forge create" is used to compile and deploy the contract.
(Reference: forge create)
Add Consumer to Adapter
In this step, the created consumer contract is added to the adapter contract and linked to your existing subscription via the adapter's addConsumer
method.
Request Randomness
We can now request randomness via the user contract with the method getRandomNumber
.
Check the Last Randomness
Finally, retrieve the last random number generated with the getLastRandomness
method.
After completing the entire process, you should have a user contract capable of requesting randomness from the Randcast adapter contract.
Last updated