Ready-to-run example
Clone the repo and run
cargo run --release -p consume-price — reads BTC/USD from the Pragma oracle on testnet, no configuration needed.How it works
Pragma Miden uses a decentralized publisher model: the oracle account stores only a registry of publisher IDs — prices live in each publisher’s own account. Consuming price data requires:- Fetching the oracle’s storage to discover all registered publisher IDs
- Importing each publisher account as a
ForeignAccount - Running a transaction script that calls
get_medianon the oracle via FPI
Step 1: Set up your project
Cargo.toml:
Step 2: Resolve the oracle’s foreign accounts
Because Pragma’s oracle depends on multiple publishers, you must import every registered publisher account alongside the oracle itself before executing the FPI call.src/main.rs:
Step 3: Call get_median via FPI
The oracle’s get_median procedure is called from a transaction script that runs against your own ephemeral account. The script pushes the pair identifier and executes FPI on the oracle.
Step 4: Run
Response format
| Stack position | Field | Description |
|---|---|---|
[0] | is_tracked | 1 if the asset has data, 0 if not registered |
[1] | median | Median price scaled by 10^6 |
[2] | amount | Echo of the input amount parameter |
1_000_000 to get the USD value.
Available assets
| faucet_id | prefix | Asset |
|---|---|---|
1:0 | 1 | BTC/USD |
2:0 | 2 | ETH/USD |
3:0 | 3 | SOL/USD |
4:0 | 4 | BNB/USD |
5:0 | 5 | XRP/USD |
6:0 | 6 | HYPE/USD |
7:0 | 7 | POL/USD |
Oracle reference
Contract addresses change between testnet iterations. Always refer to the pragma-miden README for the latest oracle ID.
CLI (quick testing)
For quick spot-checks without writing Rust, thepm-oracle-cli wraps the same logic: