How to get the BTC/USD priceInfo object and price on IOTA Move testnet with Pyth Price Feeds?

Hello!

I am working with Pyth Price Feeds on the IOTA testnet and trying to get the priceInfo object address for the BTC/USD pair. However, I get the following error when attempting to fetch the price feed:

Error: Price feed 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 not found, please create it first
    at IotaPythClient.updatePriceFeeds (/some_path_to_project/node_modules/@pythnetwork/pyth-iota-js/lib/client.js:129:23)

Support details:

  • :link: Chain: IOTA Move VM testnet
  • :test_tube: Steps to reproduce:
  1. Attempt to fetch BTC/USD priceInfo object address on IOTA testnet using IotaPythClient
  2. Receive error above
  • :receipt: Code snippet:
import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client';
import { IotaPriceServiceConnection, IotaPythClient } from "@pythnetwork/pyth-iota-js";
import { Transaction } from '@iota/iota-sdk/transactions';
export const BTC_USD_FEED: string = "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43";
const iotaClient = new IotaClient({ url: getFullnodeUrl('testnet') });
const pythClient = new IotaPythClient(iotaClient, PYTH_STATE_ID, WORMHOLE_STATE_ID);
const connection = new IotaPriceServiceConnection("https://hermes.pyth.network");
const priceUpdateData = await connection.getPriceFeedsUpdateData([BTC_USD_FEED]);
const tx = new Transaction();
const priceInfoObjectIds = await pythClient.updatePriceFeeds(tx, priceUpdateData, [BTC_USD_FEED]);
const response = await iotaClient.signAndExecuteTransaction({
        transaction: tx,
        signer: someKeypair,
    });

This code works for IOTA/USD but not for BTC/USD, ETH/USD, etc.
Could you please advise how to obtain this object and get the BTC/USD price?

hey there, thanks for the question

judging by the error, it seems that you are trying to use BTC/USD feed but the priceInfo object address is not available yet.

You can use this script to create the priceInfo object

import {
  SuiPriceServiceConnection,
  SuiPythClient,
} from '@pythnetwork/pyth-sui-js';
import { SuiClient } from '@mysten/sui.js/client';
import { TransactionBlock } from '@mysten/sui.js/transactions';
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
import dotenv from 'dotenv';

const keypair = Ed25519Keypair.fromSecretKey(
  Buffer.from(process.env.PRIVATE_KEY, 'hex')
);
const client = new SuiClient({ url: 'https://rpc-mainnet.suiscan.xyz:443' });

const connection = new SuiPriceServiceConnection('https://hermes.pyth.network');
const suiClient = new SuiPythClient(
  client,
  '0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8',
  '0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c'
); // See Hermes endpoints section below for other endpoints

const priceIds = [
  // You can find the ids of prices at https://pyth.network/developers/price-feed-ids
  '0xd40472610abe56d36d065a0cf889fc8f1dd9f3b7f2a478231a5fc6df07ea5ce3'  // ondo
];

const priceUpdateData = await connection.getPriceFeedsUpdateData([
  priceIds[0],
]);
const tx = new TransactionBlock();

const createPriceFeedRes = await suiClient.createPriceFeed(tx, priceUpdateData);

console.log('checking create feed result: ', createPriceFeedRes);

const result = await client.signAndExecuteTransactionBlock({
  signer: keypair,
  transactionBlock: tx,
  options: {
    showEffects: true,
    showEvents: true,
  },
});

console.log('checking result: ', result);

const ondoObjectId = await suiClient.getPriceFeedObjectId(priceIds[0]);

console.log('ondo object id: ', ondoObjectId);

Try using this script and let us know if it helps.

So, if I create a price feed myself, will it work fine and give correct prices?
Your code for Sui is unfortunately a bit off, as IOTA is a different blockchain, but if I understand the workflow correctly, I will customize the code for IOTA and expect normal operation

you will still be using Pyth price feed, just that you need to create the priceInfo address.

And yeah, if you could tweak that Sui script into IOTA, it should work. But let us know if it doesn’t.

@Pavlo yeah once you create the price info object it will work fine. we do have a special SDK for IOTA and you can use it. You shouldn’t need to change anything. You can see this as an example of how you can use the SDK.