arrng.io
  • Introduction
  • Supported Chains
  • How it works
  • RNG Source
  • Getting a cost estimate
  • Implementing in your contract
  • Verifiying RNG
  • Controller contract addresses
  • Fee
  • Refunds
  • arrscan.io
Powered by GitBook
On this page
  • Install the arrng package from NPM
  • Import the arrng consumer contract
  • Declare your contract as a consumer
  • Pass the controller address on the constructor
  • Request RNG
  • Receive RNG
  • Example Contract

Implementing in your contract

PreviousGetting a cost estimateNextVerifiying RNG

Last updated 1 year ago

It is very easy to implement arrng in your contract. Just follow these steps.

Install the arrng package from NPM

$ npm install @arrng/contracts

Import the arrng consumer contract

Place the following at the top of your contract in the imports section:

import {ArrngConsumer} from @arrng/contracts/ArrngConsumer.sol;

Declare your contract as a consumer

Your contract needs to declare that it is an ArrngConsumer, for example:

contract YourContract isArrngConsumer { 
  <your amazing contract here>
}

Pass the controller address on the constructor

You need to pass in the arrng controller address on your constructor call, and pass that to the consumer contract you have imported. First, .

Pass that into your constructor, and on to the consumer as follows:

constructor(address arrngController_) ArrngConsumer(arrngController_) {
  <anything else you need in your constructor>
}

Request RNG

To make a request you then simply need to call requestRandomWords on the controller, passing the native token:

arrngController.requestRandomWords {value: msg.value} (1);

Receive RNG

Finally, you need to do something with the RNG that will be passed back. To do this, override the internal function fulfillRandomness as follows:

function fulfillRandomWords(
  uint256 id, uint256[] memory numbers
  ) internal override { 
    < do something with numbers[0] > 
  }

Example Contract

I love examples!

You need a payable method that you can call to request the RNG, passing in native token for gas and the fee. See for how much to pass.

.

lookup the controller contract on your chain
getting a cost estimate
Here is an example implementation of the above