sbv2-solana/javascript/sbv2-lite
Conner Gallagher 7f2de22291 renamed repo to sbv2-solana
updated github URLs globally
2022-12-01 10:17:17 -07:00
..
src removed monorepo structure 2022-09-28 14:37:26 -06:00
tests removed monorepo structure 2022-09-28 14:37:26 -06:00
.gitignore removed monorepo structure 2022-09-28 14:37:26 -06:00
.npmignore removed monorepo structure 2022-09-28 14:37:26 -06:00
LICENSE removed monorepo structure 2022-09-28 14:37:26 -06:00
README.md removed monorepo structure 2022-09-28 14:37:26 -06:00
package-lock.json moved javascript packages to npm lock files 2022-11-28 20:23:34 -07:00
package.json renamed repo to sbv2-solana 2022-12-01 10:17:17 -07:00
tsconfig.base.json moved javascript packages to npm lock files 2022-11-28 20:23:34 -07:00
tsconfig.cjs.json removed monorepo structure 2022-09-28 14:37:26 -06:00
tsconfig.json removed monorepo structure 2022-09-28 14:37:26 -06:00

README.md

Switchboard V2 Lite

A lightweight library to decode and parse aggregator accounts

npm   twitter  

Install

npm i @switchboard-xyz/sbv2-lite

Example

import SwitchboardProgram from "@switchboard-xyz/sbv2-lite";

//

const sbv2 = await SwitchboardProgram.loadDevnet();

// SOL_USD Aggregator https://switchboard.xyz/explorer
const solAggregator = new anchor.web3.PublicKey(
  "GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR"
);

const accountInfo = await sbv2.program.provider.connection.getAccountInfo(
  solAggregator
);
if (!accountInfo) {
  throw new Error(`failed to fetch account info`);
}

// Get latest value if its been updated in the last 300 seconds
const latestResult = sbv2.decodeLatestAggregatorValue(accountInfo, 300);
if (latestResult === null) {
  throw new Error(`failed to fetch latest result for aggregator`);
}
console.log(`latestResult: ${latestResult}`);
// latestResult: 105.673205