Using the SDK

Introduction

Randcast SDK is a set of smart contracts, libraries, scripts, and examples that can be used to build a DApp or Web3 game that requires randomness. The SDK is designed to be flexible and extensible. The SDK is written in Solidity and can be used in any EVM-compatible blockchain. It aims to help request randomness as well as consume randomness in a secure and easy way. In the next sections, we will introduce how to write a consumer contract, especially for implementing the callback functions.

We recommend using Foundry to manage the dependencies, compile the project, run tests, and deploy.

Installation

forge install ARPA-Network/Randcast-User-Contract

Remapping Dependencies

You can customize these remappings by creating a remappings.txt file in the root of your project.

ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
randcast-user-contract/=lib/Randcast-User-Contract/contracts/

Usage

Now, we can import any of the contracts in Randcast-User-Contract/contracts like so:

import {
    GeneralRandcastConsumerBase,
    BasicRandcastConsumerBase
} from "randcast-user-contract/user/GeneralRandcastConsumerBase.sol";

Users can focus on the business logic of their DApp or Web3 game by using the GeneralRandcastConsumerBase. This base contract provides a simple interface for requesting randomness and receiving results.

When requesting randomness, we provide three types of randomness: Randomness, RandomWords, and Shuffling.

For experienced developers, you can directly inherit the BasicRandcastConsumerBase contract to leverage a more flexible interface for requesting randomness. You can use this contract to request randomness in any way you want. See AdvancedGetShuffledArrayExample for an example.

WARNING: You MUST restrict access to the function that requests randomness in your consumer contract. Otherwise, anyone can call this function and use your subscription to pay for randomness requests.

Examples

See Consumer Contract Examples for more details.

Last updated