> For the complete documentation index, see [llms.txt](https://docs.arrng.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arrng.io/implementing-in-your-contract.md).

# Implementing in your contract

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:

```solidity
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:

```solidity
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, [lookup the controller contract on your chain](/controller-contract-addresses.md).

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

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

## Request RNG

You need a payable method that you can call to request the RNG, passing in native token for gas and the fee. See [getting a cost estimate](/getting-a-cost-estimate.md) for how much to pass.

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

```solidity
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:

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

## Example Contract

I love examples!&#x20;

[Here is an example implementation of the above](https://github.com/arrng/arrng-contracts/blob/main/contracts/mock/MockConsumer.sol).
