# Use your first Precompiles

You are going to learn how to use kitchen precompiles. Our goal will be to implement a counter that is set to a random value using the kitchen precompiles Random.

### Implementation

We are going to modify the Counter contract located in `src/Counter.sol` it should look like this:&#x20;

<figure><img src="/files/O7T8meEvifORPOPwt5Gx" alt=""><figcaption></figcaption></figure>

First we are going to add the Random Precompile interface:

<figure><img src="/files/uo2KfH2tk9mv1BC3BCcq" alt=""><figcaption></figcaption></figure>

We will use this interface in order to call our random precompiles.

The next step is to implement our contract constructor and declare a new variable.

![](/files/2c1eW8nMHJS4lJaEp99a)\
Now we are ready to change the setNumber function. The new signature of the function will be:

```
 function setNumber() public
```

We know implement the function: !\[\[Pasted image 20250127190035.png]] Since the precompiles interface function return an array we must get the first element of the array, we only need 1 number in this case.

Since we want this contrat to be simple we will won't go further for the implementation but feel free to play with precompiles.

### Testing

Since we modified the implementation, we need to modify the test. Open the file located in `test/Counter.t.sol`

<figure><img src="/files/1MGPfpu5oIdhwAF7UHBm" alt=""><figcaption></figcaption></figure>

Since we changed the setNumber signature and it doesn't take a parameter anymore we need to change it. Remove the `testFuzz_SetNumber` test and remove the argument 0 in the `setUp` function. You will need also to create a new variable in `test_Increment` to store the counter number before updating it.&#x20;

<figure><img src="/files/KSzmCsjSccuU7IaOUiAP" alt=""><figcaption></figcaption></figure>

Now it's time to test it

⚠️ Be sure that you have foundry-kitchen installed.

In your terminal do the following command at the root of your repo.

```
forge-kitchen test
```

The output should be:&#x20;

<figure><img src="/files/mff5w8Zr3MMEaI59xaBn" alt=""><figcaption></figcaption></figure>

### Deployment

Now that we have wrote and deployed the contract we need to deploy it.

We don't need to change anything.

In order to deploy our contract we are going to do:

```
forge script script/Counter.s.sol --broadcast --rpc-url RPC_URL
--private-key PK
```

Replace RPC\_URL and PK by their value. For Private key management I recommend you to use Keystore however this will not be cover in this tutorial: <https://book.getfoundry.sh/reference/cast/cast-wallet-address>

You should normally see this:

<figure><img src="/files/OwVMaXNFhb8V47QO9rsr" alt=""><figcaption></figcaption></figure>

&#x20;To ensure that everything was smooth just copy paste the Hash address into the explorer: In our case everything is working as expected.<br>

<figure><img src="/files/rmo8XDDOrP7Yw9NUsglH" alt=""><figcaption></figcaption></figure>


---

# 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://kitchen-layer.gitbook.io/kitchen-layer-docs/developer-docs/use-your-first-precompiles.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.
