Skip to main content
This guide shows how to build a Rust application that reads on-chain price data from the Pragma oracle using Foreign Procedure Invocation (FPI).

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:
  1. Fetching the oracle’s storage to discover all registered publisher IDs
  2. Importing each publisher account as a ForeignAccount
  3. Running a transaction script that calls get_median on the oracle via FPI
The oracle performs the aggregation on-chain and returns the median to your stack.

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

Prices use 6 decimal places — divide by 1_000_000 to get the USD value.

Available assets


Oracle reference

Contract addresses change between testnet iterations. Always refer to the pragma-miden README for the latest oracle ID.
The oracle library (pm_accounts::oracle) is published as part of pragma-miden. You can add it as a git dependency or copy the compiled MASM into your own project.

CLI (quick testing)

For quick spot-checks without writing Rust, the pm-oracle-cli wraps the same logic: