# Using the random beacon on-chain

Follow this tutorial to learn how to write a smart contract that consumes randomness from Cryptosat's Random Beacon contract.

### Create and deploy Sample contract[​](https://docs.cryptosat.io/cryptosat/random-beacon/broken-reference) <a href="#create-and-deploy-contract" id="create-and-deploy-contract"></a>

In this example, we use the example client contract that is available on our Github repository- [ClientContract.sol](https://remix.ethereum.org/#url=https://raw.githubusercontent.com/cryptosat/randomness/main/contracts/ClientContract.sol)

1. Open [`ClientContract.sol` in Remix](https://remix.ethereum.org/#url=https://raw.githubusercontent.com/cryptosat/randomness/main/contracts/ClientContract.sol)
2. Go to the compiler tab, as shown below:<br>

   <div align="left"><figure><img src="https://1473078595-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl391uUK6UMTBPSQm1gpq%2Fuploads%2FZ4dgP7aD7PMQV9dwQE5D%2Fimage.png?alt=media&#x26;token=afc0dd79-5618-4676-aa18-533f5f5423f1" alt=""><figcaption></figcaption></figure></div>
3. Compile `ClientContract.sol`
4. Deploy your new contract that consumes our Random Beacon contract:&#x20;
   1. Click the Deploy & run transactions tab
   2. In the Environment drop-down menu, choose "Injected Provider - MetaMask". Don't forget to approve in the pop-up.
   3. Next to the Deploy button, enter the address of the random beacon:

* Velas Mainnet: `0x8f5FE77380B83BaA7365ccc9956EB0594859F9E4`
* Velas Testnet: `0x4a301BBC5D999C2AAfa01E299C46C654dA6C0fF7`

In this example, we'll use the Testnet address:

![](https://1473078595-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl391uUK6UMTBPSQm1gpq%2Fuploads%2FmwB8H9J5BbPNDb25kGnk%2Fimage.png?alt=media\&token=7e747872-b649-41bf-a878-ec88bc730de0)<br>

After you deploy your contract, you can interact with it.

Click on the `requestRandomWord` button to request Space Random Beacon.\
\
![](https://1473078595-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl391uUK6UMTBPSQm1gpq%2Fuploads%2FIsVRDrYyVxNOBp3uUfp6%2Fimage.png?alt=media\&token=a6183867-c15f-4315-93fb-5ee5a3461b2f)<br>

Your request has now been queued and will be submitted to the satellite. The request can take several hours to return to complete.&#x20;

Once the random number is generated, you can view it by clicking on the `random` button.

\
![](https://1473078595-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl391uUK6UMTBPSQm1gpq%2Fuploads%2FUPNuAYnEUDYvnVOhzlYN%2Fimage.png?alt=media\&token=101e7a44-de89-4aa3-8af3-bf3c5de9760a)
