> For the complete documentation index, see [llms.txt](https://banksea-finance.gitbook.io/oracle/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://banksea-finance.gitbook.io/oracle/user-guide/program-client.md).

# Program Client

Banksea Oracle aims to provide value of NFTs support on Solana. In this guide, we will teach you how to get the value (floor price, AI floor price, avg price in 24h) of collection on Solana Devnet.

## Environment Setup

Development requires rust and solana environment:

* Install [Rust](https://rustup.rs/)
* Install [Solana](https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-tool)

## Clone the example

Clone the example about Banksea Oracle:

```shell
$ git clone https://github.com/Banksea-Finance/banksea-oracle-example.git
```

## Run the example

This section will guide you how to run the Banksea Oracle example.

### Install the dependencies

```shell
$ npm install
```

### Build the program

```shell
$ cargo build-bpf
```

### Set Solana cluster to Devnet

```shell
$ solana config set --url devnet
```

### Deploy the program

```shell
$ solana program deploy target/deploy/banksea_oracle_example.so
```

### Run the test client

Run the following command to test the example program:

```shell
$ ts-node client/main.ts
```

Then, the result will be print, like following:

```shell
Answer Information: 
        degods 
        floor price is 269 SOL 
        AI floor price is 269 SOL 
        avg price is 360 SOL 
        updated on 'Fri, 22 Jul 2022 08:00:14 GMT'
```

## Review the example

In this section, we will review the example code with you.

### Cargo settings

First of all, please view the **cargo.toml** on root directory of the example project.

```rust
[package]
name = "banksea-oracle-example"
version = "0.3.0"
edition = "2018"

[dependencies]
borsh = "0.9.3"
borsh-derive = "0.9.3"
solana-program = "=1.10.29"
banksea-oracle-client = "0.4.0"

[lib]
crate-type = ["cdylib", "lib"]
```

There is **banksea-oracle** which is a rust library for Banksea Oracle. If you want to use Banksea Oracle on your program, you should copy this line to the cargo.toml on your project.

### Program

the **lib.rs** is a simple program example:

```rust
fn process_instruction(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    _instruction_data: &[u8],
) -> ProgramResult {
    let accounts_iter = &mut accounts.iter();

    let feed_account = next_account_info(accounts_iter)?;
    let answer_account = next_account_info(accounts_iter)?;

    let feed_info = banksea_oracle::get_feed_info(feed_account)?;
    let mut answer_info: Answer = try_from_slice_unchecked(&answer_account.data.borrow())?;
    answer_info.unit = feed_info.unit;
    answer_info.code = feed_info.code;
    answer_info.decimals = feed_info.decimals;
    answer_info.floor_price = feed_info.floor_price;
    answer_info.avg_price = feed_info.avg_price;
    answer_info.ai_floor_price = feed_info.ai_floor_price;
    answer_info.aggregate_time = feed_info.aggregate_time;
    answer_info.serialize(&mut &mut answer_account.data.borrow_mut()[..])?;
    
    Ok(())
}
```

1. Client will call the **process\_instruction** with **feed\_account** and **answer\_account**.
2. The **process\_instruction** call the **banksea\_oracle::get\_feed\_info** (to parse the feed\_account) and copy the result to **answer\_account**.
3. Then, the Client will print the detail of **answer\_account**.

The table below provides an overview of the fields on **FeedInfo**:

| **Field Name**         | **Description**                                         |
| ---------------------- | ------------------------------------------------------- |
| oracle                 | The oracle handle which save configure of the oracle.   |
| subscriber             | The subcriber of this feeding.                          |
| code                   | The collection code which identify a collection.        |
| unit                   | The unit of price.                                      |
| decimals               | The decimals of price.                                  |
| aggregate\_time        | The latest aggregation time.                            |
| aggregate\_node\_count | The number of nodes at the latest aggregation.          |
| floor\_price           | Minimum listing price of this collection on marketplace |
| ai\_floor\_price       | The minimum AI valuation of this collection             |
| avg\_price             | The 24 hour average price of the collection             |

### Client

The typescript client is inclue:

* **main.ts**: the program entry of client.
* **oracle.ts**: the oracle call.
* **utils.ts**: the utils of solana access.

Please View **getOracleInfo** on **oracle.ts**:

```typescript
export async function getOracleInfo(): Promise<void> {
  const feedAccountId = new PublicKey("DGaMbFh9BPZbNVWLygK4m3VhxBaNZkCumbnhpijFroaD") // It is `degods` 

  let feedAccount = {
    pubkey: feedAccountId,
    isSigner: false,
    isWritable: false,
  };

  let answer = {
    pubkey: answerPubkey,
    isSigner: false,
    isWritable: true
  };

  const instruction = new TransactionInstruction({
    keys: [feedAccount, answer],
    programId,
    data: Buffer.alloc(0),
  });

  await sendAndConfirmTransaction(
    connection,
    new Transaction().add(instruction),
    [payer],
  );


  // print the detail of answer account 
  const accountInfo = await connection.getAccountInfo(answerPubkey);
  if (accountInfo === null) {
    throw 'Error: cannot find the account';
  }

  const answerInfo = borsh.deserializeUnchecked(
    AnswerSchema,
    AnswerAccount,
    Buffer.from(accountInfo.data),
  );

  answerInfo.print();
}
```

This function is an example for getting feed information about ***DeGods***. If you want to get other collection, you can find the **Feed Account** on our site and replace the value of **feedAccountId** with it.


---

# 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://banksea-finance.gitbook.io/oracle/user-guide/program-client.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.
