How to pass Pyth updateData to smart contract?

I’m encountering an issue with fetching and formatting data from the Pyth SDK, specifically related to the update_price_data I obtain from it. In our Rust SDK, we’re using Vec<Bytes> to interact with contracts and parse responses from the Pyth service. However, when attempting to replicate this process in TypeScript, I keep running into an error message:
"FuelError: Expected array value."

To address this, I’ve explored two approaches:

#1. Making a GET request to with specific parameters:[]=${ETH_USD_PRICE_FEED_ID}&ids[]=${USDC_USD_PRICE_FEED_ID}&ids[]=${BTC_USD_PRICE_FEED_ID}

This approach results in a response like:


#2. Using the Pyth SDK and the connection.getPriceFeedsUpdateData(priceIds) method:

[‘0x01000000030d00d87b4fe955a375b8affe2de70ec1c3fba9…0000000000000000000000000000000000000000000000000’, ‘0x01000000030d006dc127b609375e3ce7ab05f8406bf3f81c…100000000007c311600000000000025c60000000065679330’, ‘0x01000000030d00ccaeca9b71f377ed31e97999e6bb2a6376…10000000005f5b8680000000000006bb00000000065679331’, ‘0x01000000030d00e67af2a8984d0cffad22b77c619b1bbccf…1000000019faf1633000000000044c1110000000065679331’, ‘0x01000000030d00885058f5cfb4e8a5bbe37f395258a7b74b…f000000012ef0cbc500000000005f625e000000006567932b’]

I’ve attempted to parse both of these values using the following method:

const parsedUpdateData = => Uint8Array.from(v.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))));

Afterwards, I’ve provided this parsed data to a contract method that expects arguments of this type:

withdraw_collateral: InvokeFunction<[amount: BigNumberish, price_update_data: Vec<Bytes>], void>;

However, this approach failed with the same error message: "FuelError: Expected array value."If you have any insights or examples on how to correctly format and provide this data, I would greatly appreciate it

Hi there!

You might try to use our built in helper “arrayify”, defined here.

import { arrayify } from "fuels";

That will give you a proper byte array.

Let me know if this works!

yep, it worked like this
const parsedUpdateData = => Array.from(arrayify(v)))

1 Like

I’m glad it worked!

I’ve opened an issue to make the Vector encode to support uInt8Array.


This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.