> ## Documentation Index
> Fetch the complete documentation index at: https://docs.berachain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pyth Oracle on Berachain

> Query Pyth Network price data on Berachain with on-demand updates. Deploy consumer contract, fetch price payload, call updatePrice and getPrice.

Use this guide when you need **real-time price data** or **oracle feeds** on Berachain. Pyth uses on-demand updates: your contract pulls the latest price when needed instead of subscribing to a stream.

## Repository

* **Code:** [github.com/berachain/guides/tree/main/apps/pyth-oracle](https://github.com/berachain/guides/tree/main/apps/pyth-oracle)
* **README (raw):** [raw README](https://raw.githubusercontent.com/berachain/guides/main/apps/pyth-oracle/README.md)

## Official documentation

* [Pyth Network](https://pyth.network/) — oracle overview and on-demand model.

## Requirements

* Node `v20.11.0` or greater, npm
* [jq](https://jqlang.github.io/jq/download/)
* Wallet with testnet \$BERA — [Bepolia Faucet](https://bepolia.faucet.berachain.com)
* [Foundry](https://book.getfoundry.sh/getting-started/installation)

## Stack

Solidity, Foundry (Forge, Cast), Node.js, Pyth Hermes API (price payloads).

## Quick start

1. **Clone and install**
   ```bash theme={null}
   git clone https://github.com/berachain/guides.git && cd guides/apps/pyth-oracle
   npm install
   ```
2. **Import wallet** (Foundry keystore): `cast wallet import deployer --interactive`. Set `BERACHAIN_TESTNET_RPC` (e.g. `https://bepolia.rpc.berachain.com`).
3. **Deploy consumer contract**
   ```bash theme={null}
   forge build
   forge create ./src/ConsumerContract.sol:ConsumerContract --rpc-url $BERACHAIN_TESTNET_RPC --account deployer
   ```
4. **Fetch price and update on-chain**
   ```bash theme={null}
   curl -s "https://hermes.pyth.network/v2/updates/price/latest?&ids[]=0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace" | jq -r ".binary.data[0]" > price_update.txt
   cast send <CONTRACT> --rpc-url $BERACHAIN_TESTNET_RPC "updatePrice(bytes[])" "[0x\`cat price_update.txt\`]" --account deployer --value 0.0001ether
   ```
5. **Read price:** `cast call <CONTRACT> --rpc-url $BERACHAIN_TESTNET_RPC "getPrice()"`

**Troubleshooting:** `StalePrice` — re-run the update; `InsufficientFee` — increase `--value` (e.g. `0.0005ether`).

## Key files

| Purpose           | Path                       |
| ----------------- | -------------------------- |
| Consumer contract | `src/ConsumerContract.sol` |
