@renec-foundation/oracle-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

oracle-sdk

How to use

import {
  PublicKey,
  Connection,
  Keypair,
  Commitment,
} from "@solana/web3.js";
import { AnchorProvider, Wallet, BN, Address } from "@project-serum/anchor";
import { Context, ProductClient, 
  ORACLE_PROGRAM_ID, REUSD, REVND, VERSION 
} from "@renec-foundation/oracle-sdk";


...
// yourKey = Keypair.fromSecretKey(Uint8Array.from([124, 149, 222, 31, 236, 142, 29, 95...]));

const commitment: Commitment = "confirmed";
const connection = new Connection(consts.RPC_ENDPOINT_URL, { commitment });
const wallet = new Wallet(yourKey);
const provider = new AnchorProvider(connection, wallet, { commitment });

const ctx = Context.withProvider(provider, ORACLE_PROGRAM_ID);


const base = REUSD;
const quote = REVND;
const newPrice = 24500.35;

const productClient = await ProductClient.getProduct(ctx, quote, base, VERSION);
const tx = await productClient.postPrice(
    newPrice,
    productClient.ctx.wallet.publicKey
);

await tx.buildAndExecute();
await productClient.refresh();

const price = await productClient.getPrice();
console.log("price", price);
  • Output
price {
  "price": 25000,
  "symbol": "VND/USD",
  "timestamp": 1686731721,
  "numberPublishers": 1
}

Readme

Keywords

none

Package Sidebar

Install

npm i @renec-foundation/oracle-sdk

Weekly Downloads

69

Version

0.1.5

License

Apache-2.0

Unpacked Size

212 kB

Total Files

50

Last publish

Collaborators

  • renec-foundation