> For the complete documentation index, see [llms.txt](https://docs.relink.services/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.relink.services/architecture/installation-and-setup/soroban-rust.md).

# Soroban / Rust

### Smart Contracts

To use Relink Protocol from your Soroban contract, and let users request Chainlink data, make use of our consumer contract lib and call the public functions as shown below.

Note: to always get the most up to date information about the library, please see the README of the repo here: [**https://github.com/RelinkServices/relink-contracts-rust-soroban**](https://github.com/RelinkServices/relink-contracts-rust-soroban)

{% hint style="danger" %}
**Attention:** The following code is for showcase purposes only and is not production ready.
{% endhint %}

```rust
use soroban_sdk::{contract, contractimpl, Address, BytesN, Env, Map, Vec};

use relink::{consumer, Error, RequestId, VrfDirectFundingConsumer};

mod events;
mod storage;
mod test;

#[contract]
pub struct VrfDirectFundingConsumerExample;

#[contractimpl]
impl VrfDirectFundingConsumerExample {
    /// Initialize contract by setting the proxy address and trusted oracles.
    pub fn initialize(env: Env, proxy: Address, threshold: u32, oracles: Vec<BytesN<32>>) {
        consumer::init(&env, &proxy, threshold, oracles);
    }

    /// Initiate a request for randomness.
    pub fn initiate_randomness_request(env: Env, origin: Address, value: i128) -> RequestId {
        let id = consumer::request_randomness(&env, origin, value, None, None);
        // store the request id until the response is processed
        storage::add_request_id(&env, id.clone());
        id
    }
}

#[contractimpl]
impl VrfDirectFundingConsumer for VrfDirectFundingConsumerExample {
    /// Process the response to a randomness request.
    fn verify_and_fulfill_randomness(
        env: Env,
        id: RequestId,
        request_origin: Address,
        random_words: Vec<BytesN<32>>,
        signatures: Map<BytesN<32>, BytesN<64>>,
    ) -> Result<(), Error> {
        // check if RequestId exists
        storage::has_request_id(&env, id.clone())?;
        // verify signatures
        consumer::verify_randomness(&env, &id, &request_origin, &random_words, &signatures)?;
        // remove request as it should only be handled once
        storage::remove_request_id(&env, id.clone());
        // emit event containing the provided random words
        events::randomness_provided(&env, id, random_words);
        Ok(())
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.relink.services/architecture/installation-and-setup/soroban-rust.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
