---
sidebar_position: 20
title: Oracles
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

## Create

- `oracleInit`

<Tabs>
  <TabItem value="Typescript" label="Typescript" default>

```ts
import * as anchor from "@project-serum/anchor";
import { Keypair } from "@solana/web3.js";
import {
  loadSwitchboardProgram,
  OracleAccount,
  OracleQueueAccount,
} from "@switchboard-xyz/switchboard-v2";

let payer: Keypair;
const program = await loadSwitchboardProgram("devnet", undefined, payer);

const queueAccount = new OracleQueueAccount({
  program,
  publicKey: queuePubkey,
});

// Create oracle
const oracleAccount = await OracleAccount.create(program, {
  name: Buffer.from("My Oracle"),
  queueAccount,
});
```

  </TabItem>
  <TabItem value="CLI" label="CLI">

```bash
sbv2 oracle create QUEUEKEY \
    --name "My Oracle" \
    --keypair "path/to/payer/keypair.json" \
    --authority "path/to/authority/keypair.json"  \
    --enable \
    --verbose
```

  </TabItem>
</Tabs>

## Oracle Deposit

- `tokenTransfer`

<Tabs>
  <TabItem value="Typescript" label="Typescript" default>

```ts
import * as anchor from "@project-serum/anchor";
import { Keypair } from "@solana/web3.js";
import {
  loadSwitchboardProgram,
  OracleAccount,
  OracleQueueAccount,
} from "@switchboard-xyz/switchboard-v2";

let payer: Keypair;
let amount = new anchor.BN(1_000_000_000);
const program = await loadSwitchboardProgram("devnet", undefined, payer);

const oracleAccount = new OracleAccount({ program, publicKey: oracleKey });
const oracle = await oracleAccount.loadData();

const queueAccount = new OracleQueueAccount({
  program,
  publicKey: oracle.queuePubkey,
});
const mint = await queueAccount.loadMint();
const funderTokenAccount = (
  await mint.getOrCreateAssociatedAccountInfo(payer.publicKey)
).address;

const signature = await mint.transfer(
  funderTokenAccount,
  oracle.tokenAccount,
  payer,
  [],
  amount.toNumber()
);
```

  </TabItem>
  <TabItem value="CLI" label="CLI">

```bash
sbv2 oracle deposit ORACLEKEY \
   --keypair "path/to/payer/keypair.json" \
   --amount 1.25
```

  </TabItem>
</Tabs>

## Oracle Withdraw

- `oracleWithdraw`

<Tabs>
  <TabItem value="Typescript" label="Typescript" default>

```ts
import * as anchor from "@project-serum/anchor";
import { Keypair } from "@solana/web3.js";
import {
  loadSwitchboardProgram,
  OracleAccount,
  OracleQueueAccount,
} from "@switchboard-xyz/switchboard-v2";

let payer: Keypair;
let amount = new anchor.BN(1_000_000_000);
const program = await loadSwitchboardProgram("devnet", undefined, payer);

const oracleAccount = new OracleAccount({ program, publicKey: oracleKey });
const oracle = await oracleAccount.loadData();

const queueAccount = new OracleQueueAccount({
  program,
  publicKey: oracle.queuePubkey,
});
const mint = await queueAccount.loadMint();
const withdrawAccount = (
  await mint.getOrCreateAssociatedAccountInfo(payer.publicKey)
).address;

const signature = await oracleAccount.withdraw({
  amount,
  oracleAuthority: payer,
  withdrawAccount,
});
```

  </TabItem>
  <TabItem value="CLI" label="CLI">

```bash
sbv2 oracle withdraw ORACLEKEY \
    --keypair "path/to/payer/keypair.json" \
    --amount 1.25
```

  </TabItem>
</Tabs>
