Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pythnetwork/client

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pythnetwork/client

Client for consuming Pyth price data

  • 2.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36K
increased by40.43%
Maintainers
3
Weekly downloads
 
Created
Source

@pythnetwork/client

A library for reading on-chain Pyth oracle data

Pyth is building a way to deliver a decentralized, cross-chain market of verifiable data from high-quality nodes to any smart contract, anywhere.

This library reads on-chain Pyth data from @solana/web3.js and returns JavaScript-friendly objects.

See our examples repo for real-world usage examples.

Installation

npm

$ npm install --save @pythnetwork/client

Yarn

$ yarn add @pythnetwork/client

Example Usage

This library provides a subscription model for consuming price updates:

const pythConnection = new PythConnection(solanaWeb3Connection, getPythProgramKeyForCluster(solanaClusterName))
pythConnection.onPriceChange((product, price) => {
  // sample output:
  // SRM/USD: $8.68725 ±$0.0131
  console.log(`${product.symbol}: $${price.price} \xB1$${price.confidence}`)
})

// Start listening for price change events.
pythConnection.start()

The onPriceChange callback will be invoked every time a Pyth price gets updated. This callback gets two arguments:

  • price contains the official Pyth price and confidence, along with the component prices that were combined to produce this result.
  • product contains metadata about the price feed, such as the symbol (e.g., "BTC/USD") and the number of decimal points.

See src/example_usage.ts for a runnable example of the above usage. You can run this example with npm run example.

You may also register to specific account updates using connection.onAccountChange in the solana web3 API, then use the methods in index.ts to parse the on-chain data structures into Javascript-friendly objects.

Keywords

FAQs

Package last updated on 28 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc