# @switchboard-xyz/sui.js

> API wrapper for intergating with the Switchboardv2 program on sui

Latest version **2.3.17** (published 2024-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @switchboard-xyz/sui.js
pnpm add @switchboard-xyz/sui.js
yarn add @switchboard-xyz/sui.js
bun add @switchboard-xyz/sui.js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.17 |
| Published | 2024-02-24 |
| First published | 2022-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 460.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | anoushk, gallynaut, herm, vjessup, mgild, jessupjn |

## Links

- npm: https://www.npmjs.com/package/@switchboard-xyz/sui.js
- npm.io page: https://npm.io/package/@switchboard-xyz/sui.js

## Dependencies (5)

- [chalk](https://npm.io/package/chalk.md) ^5.0.1
- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [node-fetch](https://npm.io/package/node-fetch.md) 3.3.1
- [@mysten/sui.js](https://npm.io/package/@mysten/sui.js.md) 0.32.2
- [@switchboard-xyz/common](https://npm.io/package/@switchboard-xyz/common.md) ^2.3.3

## Recent versions

- 2.3.17 (latest) — 2024-02-24
- 2.3.18-beta.0 (beta) — 2024-03-26
- 2.3.17-beta.1 — 2024-02-22
- 2.3.17-beta.0 — 2024-02-22
- 2.3.16 — 2024-01-30
- 2.3.15-beta.1 — 2024-01-30
- 2.3.15-beta.0 — 2024-01-30
- 2.3.15 — 2024-01-30
- 2.3.14 — 2023-12-22
- 2.3.14-beta.0 — 2023-12-05
- 2.3.13 — 2023-05-12
- 2.3.12 — 2023-05-05
- 2.3.11 — 2023-05-01
- 2.3.10 — 2023-04-17
- 2.3.9 — 2023-04-17
- … 14 more at https://npm.io/package/@switchboard-xyz/sui.js/versions

## README

<div align="center">

![Switchboard Logo](https://github.com/switchboard-xyz/sbv2-core/raw/main/website/static/img/icons/switchboard/avatar.png)

# @switchboard-xyz/sui.js

> A Typescript client to interact with Switchboard V2 on Sui.

[![NPM Badge](https://img.shields.io/github/package-json/v/switchboard-xyz/sbv2-sui?color=red&filename=javascript%2Fsui.js%2Fpackage.json&label=%40switchboard-xyz%2Fsui.js&logo=npm)](https://www.npmjs.com/package/@switchboard-xyz/sui.js)

</div>

## Install

```bash
npm i --save @switchboard-xyz/sui.js
```

## Usage

**Directory**

- [Reading Feeds](#reading-feeds)
- [Creating Feeds](#creating-feeds)

### Reading Feeds

```ts
import { AggregatorAccount } from "@switchboard-xyz/sui.js";

const aggregatorAccount: AggregatorAccount = new AggregatorAccount(
  client,
  aggregator_address,
  SWITCHBOARD_ADDRESS
);

console.log(await aggregatorAccount.loadData());
```

### Creating Feeds

```ts
import { Buffer } from "buffer";
import { OracleJob, createFeed } from "@switchboard-xyz/sui.js";
import Big from "big.js";
import {
Ed25519Keypair,
JsonRpcProvider,
devnetConnection,
} from "@mysten/sui.js";

// devnet address
const SWITCHBOARD_ADDRESS = "0x23ecb0df7bed0b4048f939298c9a179973e13d4e";
const QUEUE_ADDRESS = "0xacbb5327b76a6980495f4f3b7482c7f6cc5a4791";

// keypair
const keypair = Ed25519Keypair.fromSecretKey(Buffer.from(/** YOUR KEYPAIR IMPORT GOES HERE **/, "hex"));

// Make Job data for btc price
const serializedJob = Buffer.from(
OracleJob.encodeDelimited(
  OracleJob.create({
    tasks: [
      {
        httpTask: {
          url: "https://www.binance.us/api/v3/ticker/price?symbol=BTCUSD",
        },
      },
      {
        jsonParseTask: {
          path: "$.price",
        },
      },
    ],
  })
).finish()
);

const coins = await provider.selectCoinsWithBalanceGreaterThanOrEqual(
userAddress,
BigInt(10000000)
);

const coin: any = coins.pop();

const [aggregator, createFeedTx] = await createFeed(
provider,
keypair, // you will need to import a Sui Payer Keypair
{
  name: "BTC/USD",
  authority: userAddress,
  queueAddress: queue.address,
  batchSize: 1,
  minJobResults: 1,
  minOracleResults: 1,
  minUpdateDelaySeconds: 5,
  varianceThreshold: new Big(0),
  forceReportPeriod: 0,
  coinType: "0x2::sui::SUI",
  initialLoadAmount: 1,
  loadCoin: coin.details.reference.objectId,
  jobs: [
    {
      name: "BTC/USD",
      data: Array.from(serializedJob1),
      weight: 1,
    },
  ],
},
SWITCHBOARD_ADDRESS
);

console.log(`Created Aggregator address ${aggregator.address}.`);
```

---
_Source: https://npm.io/package/@switchboard-xyz/sui.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
