Use Randcast CLI

Randcast users can leverage our Randcast CLI tool to manage their subscription and consumer contracts, read and filter historical requests and fulfillment results, and estimate the gas cost of the callback function, all in one place.

Note: This is our recommended method to interact with Randcast, but we also offer additional methods, such as direct contract interaction, in the following section.

Prerequisites

  • Smart Contract development experience in Solidity

  • Experience with Foundry Solidity development toolkit

Installation

  • (Recommended) Install from Docker image

    • docker pull arpachainio/user-shell:latest

  • (Optional) Build from the codebase

Usage

docker run -it -v <WORK_DIR>:/data ghcr.io/arpa-network/user-shell:latest "user-shell -c /data/user_config.yml -H /data/user-shell.history"
  • create a <WORK_DIR> as the directory for Randcast CLI on your host, e.g. /home/ubuntu/randcast-cli

  • prepare a user_config.yml under <WORK_DIR> of your host. Please see the example for reference.

Note: we recommend directly setting account identity in user_config.yml rather than passing an env variable to docker.

  • use -H to set a file to save history commands.

  • --network=host(optional config for local chains) If you want the Randcast CLI container to access a local chain on the host (ex: Anvil), you can use the above flag. This will allow the container to access ports on the localhost such as "http://127.0.0.1:8545".

Steps

Note: Always use [COMMAND] -h to get help.

Create a subscription:


Get subscriptions(<SUB_ID>):


Write and deploy a consumer contract. Here we use forge from Foundry to complete this step.

Note that --rpc-url is needed unless you are performing tests using a local chain:

(Reference: forge create)


Bind the consumer contract to the subscription:


Check a specific subscription to make sure that a consumer contract has been added:


Estimate gas cost for the fulfillment of the first request:


Fund the subscription with a little more than the estimated payment amount to cover the surge in gas price:


The subscription should be ready to use now, double-check it:


Request randomness in any way that you need. Here we use cast from Foundry (note that --rpc-url is needed unless you are using a local chain):

(Reference: cast send)


Query historical randomness requests paid by the subscription

Note: it is possible to add an optional filter to filter by consumer address or by status (pending / success / failed). You can view these options by running randcast rs --help.

Last updated