Smart contract reverts when sending Pyth price updates via HermesClient from my frontend

The transaction always reverts as soon as I include the price update in the call parameters. If I replace it with an empty array, the transaction succeeds. Am I passing the price update data correctly?

:link: Chain

Base

:stopwatch: Timestamp

2025-04-25 08:30 UTC

:test_tube: Steps to reproduce

const connection = new HermesClient("https://hermes.pyth.network", {});
const priceIds = ["0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"]; //BTC

// Latest price updates
const priceUpdates = await connection.getLatestPriceUpdates(priceIds);

const data = encodeFunctionData({
        abi: FuturesABI,
        functionName: "modifyPosition",
        args: [
          //Other arguments....,
          priceUpdates.binary.data,
        ],
      });

@cuardiper How does your contract interact with Pyth? I suspect that you are not paying the update fee.

This is the snippet of the code from the smart contract that interact with pyth to update the price:

function modifyPosition(
        uint256 collateral,
        bytes32 key,
        //other params...
        bytes[] calldata priceUpdate
    ) external {
        uint pythFee = pyth.getUpdateFee(priceUpdate);
        pyth.updatePriceFeeds{ value: pythFee }(priceUpdate);
        //...

The smart contract has some eth to pay the fee

@cuardiper Can you tell us what is the revert code you see?

Hey, this is an example of a transaction that fails:

Hello, I omitted the smart account part and now I am sending the tx directly through the metamask to see if there was any more clear message. Any clue on how to keep debugging that or what could be the issue?

Where are you sending this contract?
Which contract is this?
0xA62C31A48aD402245eAa8B9D3a5D2f1e61e74e06

Pyth contract on base is
https://basescan.org/address/0x8250f4aF4B972684F7b336503E2D6dFeDeB1487a

That is our own smart contract, from our smart contract is that we will call the updatePriceFeeds. Something like this:

import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
//...

function modifyPosition(
        uint256 collateral,
        bytes32 key,
        //other params...
        bytes[] calldata priceUpdate
    ) external {
        uint pythFee = pyth.getUpdateFee(priceUpdate);
        pyth.updatePriceFeeds{ value: pythFee }(priceUpdate);
        //...

Can you make sure that the msg.value is being passed correctly?
Make sure your contract has enough balance to cover it?

If yes, can you share the transaction as well verify the contracts to help us debug.

Yes, we already sent more than enough Base ETH to the contract to pay the fee. It has around $10 (0.00307 ETH). Exactly same amount as we started, did not spent any of it on the multiple attempts we did.

I am going to ask team to verify the contract

1 Like

Fixed, in case it helps someone…I had to append a “0x” to the update elements before calling the smart contract, here is the code:


let updatesToSend = [];
      if (priceUpdates.binary.data) {
        //Loop each priceUpdate and append "0x" at the start
        updatesToSend = priceUpdates.binary.data.map((update) => {
          return "0x" + update;
        });
      }

const data = encodeFunctionData({
        abi: FuturesABI,
        functionName: "modifyPosition",
        args: [
          //Other arguments....,
          updatesToSend,
        ],
      });