npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pythnetwork/pyth-ton-js

v0.4.0

Published

Pyth Network TON Utilities

Readme

Pyth Network TON SDK

This SDK provides a JavaScript interface for interacting with the Pyth Network on the TON blockchain.

Installation

npm install @pythnetwork/pyth-ton-js

Usage

Here's a basic example of how to use the SDK:

npm install @pythnetwork/pyth-ton-js @pythnetwork/hermes-client @ton/core @ton/ton @ton/crypto
import { TonClient, Address, WalletContractV4 } from "@ton/ton";
import { toNano } from "@ton/core";
import { mnemonicToPrivateKey } from "@ton/crypto";
import { HermesClient } from "@pythnetwork/hermes-client";
import {
  PythContract,
  PYTH_CONTRACT_ADDRESS_TESTNET,
  calculateUpdatePriceFeedsFee,
} from "@pythnetwork/pyth-ton-js";

const BTC_PRICE_FEED_ID =
  "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43";

async function main() {
  const client = new TonClient({
    endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC",
    apiKey: "your-api-key-here", // Optional, but note that without api-key you need to send requests once per second
  });

  const contractAddress = Address.parse(PYTH_CONTRACT_ADDRESS_TESTNET);
  const contract = client.open(PythContract.createFromAddress(contractAddress));

  const guardianSetIndex = await contract.getCurrentGuardianSetIndex();
  console.log("Guardian Set Index:", guardianSetIndex);

  const price = await contract.getPriceUnsafe(BTC_PRICE_FEED_ID);
  console.log("BTC Price from TON contract:", price);

  const hermesEndpoint = "https://hermes.pyth.network";
  const hermesClient = new HermesClient(hermesEndpoint);

  const priceIds = [BTC_PRICE_FEED_ID];
  const latestPriceUpdates = await hermesClient.getLatestPriceUpdates(
    priceIds,
    {
      encoding: "hex",
    }
  );
  console.log("Hermes BTC price:", latestPriceUpdates.parsed?.[0].price);

  const numUpdates = 1; // Only BTC price
  const updateData = Buffer.from(latestPriceUpdates.binary.data[0], "hex");
  console.log("Update data:", updateData);

  // NOTE: As of 2025/10/19 There's a bug with TON Access (https://ton.access.orbs.network) RPC service where if you provide an
  // update data buffer with length of more than ~320 then the rpc returns error 404 and the function fails. In this case you can use the
  // contract.getSingleUpdateFee() method to get the single update fee and multiply it by the number of updates you want to perform.
  const updateFee = await contract.getUpdateFee(updateData);
  console.log("Update fee:", updateFee);

  const mnemonic = "your mnemonic here";
  const key = await mnemonicToPrivateKey(mnemonic.split(" "));
  const wallet = WalletContractV4.create({
    publicKey: key.publicKey,
    workchain: 0,
  });
  const provider = client.open(wallet);

  await contract.sendUpdatePriceFeeds(
    provider.sender(key.secretKey),
    updateData,
    calculateUpdatePriceFeedsFee(numUpdates) + BigInt(updateFee)
  );
  console.log("Price feeds updated successfully.");

  const updatedPrice = await contract.getPriceUnsafe(BTC_PRICE_FEED_ID);
  console.log("Updated BTC Price from TON contract:", updatedPrice);
}

main().catch(console.error);

API Reference

PythContract

The main class for interacting with the Pyth contract on TON.

Methods:

  • getCurrentGuardianSetIndex(provider: ContractProvider): Promise<number>
  • getPriceUnsafe(provider: ContractProvider, priceFeedId: string): Promise<PriceInfo>
  • getPriceNoOlderThan(provider: ContractProvider, timePeriod: number, priceFeedId: string): Promise<PriceInfo>
  • getEmaPriceUnsafe(provider: ContractProvider, priceFeedId: string): Promise<PriceInfo>
  • getEmaPriceNoOlderThan(provider: ContractProvider, timePeriod: number, priceFeedId: string): Promise<PriceInfo>
  • getUpdateFee(provider: ContractProvider, vm: Buffer): Promise<number>
  • getSingleUpdateFee(provider: ContractProvider): Promise<number>
  • sendUpdatePriceFeeds(provider: ContractProvider, via: Sender, updateData: Buffer, updateFee: bigint): Promise<void>

Constants

  • PYTH_CONTRACT_ADDRESS_TESTNET: The address of the Pyth contract on the TON testnet.