ARPA Network
  • ARPA Network
  • Becoming a node & get rewarded
    • Native Staking
      • Introduction to Staking v0.1
    • Eigenlayer Integration
  • Randcast
    • Getting Started
      • Use Web GUI
        • Subscription Management Portal
        • Remix
      • Use Randcast CLI
      • Use Solidity Development Tools
    • Using the SDK
      • Adapter
      • BasicRandcastConsumerBase
      • GeneralRandcastConsumerBase
      • Randcast Utilities
      • Consumer Contract Examples
        • Example - Get Random Number
        • Example - Roll a Dice
        • Example - Shuffle an Array
        • Example - Draw a Lottery
        • Example - Pick a Property
        • Example - Pick a Rarity
        • Example - Pick a Winner
        • Example - Advanced Request
    • Supported Networks & Parameters
  • GitHub Repositories
Powered by GitBook
On this page
  • Prerequisites
  • Installation
  • Steps
  1. Randcast
  2. Getting Started

Use Solidity Development Tools

PreviousUse Randcast CLINextUsing the SDK

Last updated 1 year ago

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 , , or programmatically, we recommend using from the framework.

Prerequisites

  • Smart Contract development experience in Solidity

  • Experience with Solidity development toolkit

Installation

  • Install

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 .

export ADAPTER_CONTRACT=0xbd57b868bb3374faa88722d2ee7ba3023c744e05 # mainnet adapter contract
export RPC_URL= # Mainnet Alchemy / Infura RPC URL Here
export USER_PUBLIC_KEY= # Eth User You are using to deploy consumer / user contract
export USER_PRIVATE_KEY= # Corresponding Private Key

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.

cast block-number --rpc-url $RPC_URL # This will be useful for step 3
cast send $ADAPTER_CONTRACT "createSubscription()(uint64)" --private-key $USER_PRIVATE_KEY --rpc-url $RPC_URL  # returns subid

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.

cast logs --from-block 174270 --to-block latest 'SubscriptionCreated(uint64 indexed subId, address indexed owner)' "" $USER_PUBLIC_KEY --address $ADAPTER_CONTRACT --rpc-url $RPC_URL

#   topics: [ . # Sample response topics
#       0x464722b4166576d3dcbba877b999bc35cf911f4eaf434b7eba68fa113951d0bf # event sig
#       0x0000000000000000000000000000000000000000000000000000000000000001 # subId
#       0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8 # user public key
#   ]
export SUB_ID= # export subid for your newly created subscription

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

cast send $ADAPTER_CONTRACT "fundSubscription(uint64)" $SUB_ID --value 1ether --private-key $USER_PRIVATE_KEY --rpc-url $RPC_URL

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.

git clone https://github.com/ARPA-Network/Randcast-User-Contract
cd Randcast-User-Contract
forge create --rpc-url $RPC_URL --private-key $USER_PRIVATE_KEY contracts/user/examples/GetRandomNumberExample.sol:GetRandomNumberExample --constructor-args $ADAPTER_CONTRACT

export USER_CONTRACT= # export address for your newly deployed user contract

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.

cast send $ADAPTER_CONTRACT "addConsumer(uint64, address)" $SUB_ID $USER_CONTRACT --private-key $USER_PRIVATE_KEY --rpc-url $RPC_URL

Request Randomness

We can now request randomness via the user contract with the method getRandomNumber.

cast send $USER_CONTRACT "getRandomNumber()" --private-key $USER_PRIVATE_KEY --rpc-url $RPC_URL

Check the Last Randomness

Finally, retrieve the last random number generated with the getLastRandomness method.

cast call $ADAPTER_CONTRACT "getLastRandomness()(uint256)" --rpc-url $RPC_URL

After completing the entire process, you should have a user contract capable of requesting randomness from the Randcast adapter contract.

(Reference: )

(Reference: )

If needed, you can use the to estimate how much ETH each randomness request will cost.

(Reference: )

Remix
Etherscan
Cast
Foundry
Foundry
Foundry
Supported Networks & Parameters
cast send
cast logs
forge create
Randcast CLI dryrun