Skip to content

Handle price feed data correctly #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timothymcmackin
Copy link

Description

Not 100% sure about this but I think this change is correct, and it works on Etherlink Testnet.

As you can see in the curl -s "https://hermes.pyth.network/v2/updates/price/latest?&ids[]=$ETH_USD_ID" | jq -r ".binary.data[0]" > price_update.txt call earlier in this tutorial, Hermes returns data structured like this:

{
  "binary": {
    "encoding": "hex",
    "data": [
      "[DATA]"
    ]
  },
  "parsed": [
    {
      "id": "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
      "price": {
        "price": "275245000000",
        "conf": "184832512",
        "expo": -8,
        "publish_time": 1749736319
      },
      "ema_price": {
        "price": "274167870000",
        "conf": "144995090",
        "expo": -8,
        "publish_time": 1749736319
      },
      "metadata": {
        "slot": 222966497,
        "proof_available_time": 1749736320,
        "prev_publish_time": 1749736319
      }
    }
  ]
}

When you call Pyth, you pass just [DATA], or .binary.data[0]. As it is, the JS code passes the whole JSON object, not just .binary.data[0]:

const priceFeedUpdateData = await connection.getLatestPriceUpdates(priceIds);
// ...
const hash = await contract.write.updateAndMint(
  [priceFeedUpdateData.binary.data as any],
  { value: parseEther("0.0005") }
);

This works for me on Etherlink Testnet when I change it to access the right part of the object and prefix it as a binary:

const hash = await contract.write.updateAndMint(
  [[`0x${priceFeedUpdateData.binary.data[0]}`]] as any,
  { value: parseEther("0.0005") },
);

Type of Change

  • New Page
  • Page update/improvement
  • Fix typo/grammar
  • Restructure/reorganize content
  • Update links/references
  • Other (please describe):

Areas Affected

Checklist

  • I ran pre-commit run --all-files to check for linting errors
  • I have reviewed my changes for clarity and accuracy
  • All links are valid and working
  • Images (if any) are properly formatted and include alt text
  • Code examples (if any) are complete and functional
  • Content follows the established style guide
  • Changes are properly formatted in Markdown
  • Preview renders correctly in development environment

Related Issues

Closes #

Additional Notes

Contributor Information

  • Name:
  • Email:

Screenshots

Copy link

vercel bot commented Jun 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 1:57pm

Copy link

vercel bot commented Jun 12, 2025

@timothymcmackin is attempting to deploy a commit to the Pyth Network Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant