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
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.
CLI (quick testing)
For quick spot-checks without writing Rust, thepm-oracle-cli wraps the same logic: