# 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](https://remix.ethereum.org/), [Etherscan](https://etherscan.io/address/0xbd57b868bb3374faa88722d2ee7ba3023c744e05), or programmatically, we recommend using [Cast ](https://book.getfoundry.sh/cast/)from the [Foundry](https://github.com/foundry-rs/foundry) framework.

### Prerequisites&#x20;

* Smart Contract development experience in Solidity&#x20;
* Experience with [Foundry](https://github.com/foundry-rs/foundry) Solidity development toolkit

### Installation

* Install [Foundry](https://book.getfoundry.sh/getting-started/installation)

### 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.&#x20;

Note: the adapter contract address for the chain you are using can be found on the [Supported Networks & Parameters](/randcast/supported-networks-and-parameters.md).

```bash
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.

*(Reference:* [*cast send*](https://book.getfoundry.sh/reference/cast/cast-send)*)*

```bash
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.

*(Reference:* [*cast logs*](https://book.getfoundry.sh/reference/cast/cast-logs)*)*

```bash
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.&#x20;

Note: Recommended eth amounts:

* OP Goerli / Mainnet: 0.01 ETH
* Sepolia: 0.1 ETH

If needed, you can use the [Randcast CLI dryrun](/randcast/getting-started/use-randcast-cli.md#estimate-gas-cost-for-the-fulfillment-of-the-first-request) to estimate how much ETH each randomness request will cost.&#x20;

```bash
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.

*(Reference:* [*forge create*](https://book.getfoundry.sh/forge/deploying)*)*

```bash
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.

```bash
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`.

```bash
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.

```bash
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arpanetwork.io/randcast/getting-started/use-solidity-development-tools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
