Skip to main content

How to use the popCapsule oracle

On this page you will learn how to use the popCapsule oracle. To see what other oracles are available in Aztec.nr, go here.

How to use the popCapsule oracle

popCapsule is used for passing artbitrary data. We have not yet included this in Aztec.nr, so it is a bit more complex than the other oracles. You can follow this how-to:

1. Define the pop_capsule function

In a new file on the same level as your main.nr, implement an unconstrained function that calls the pop_capsule oracle:

pop_capsule
#[oracle(popCapsule)]
fn pop_capsule_oracle<N>() -> [Field; N] {}

// A capsule is a "blob" of data that is passed to the contract through an oracle.
unconstrained pub fn pop_capsule<N>() -> [Field; N] {
pop_capsule_oracle()
}
Source code: noir-projects/noir-contracts/contracts/slow_tree_contract/src/capsule.nr#L1-L9

2. Import this into your smart contract

If it lies in the same directory as your smart contract, you can import it like this:

import_pop_capsule
use crate::capsule::pop_capsule;
Source code: noir-projects/noir-contracts/contracts/slow_tree_contract/src/main.nr#L19-L21

3. Use it as any other oracle

Now it becomes a regular oracle you can call like this:

pop_capsule
let fields = pop_capsule();
Source code: noir-projects/noir-contracts/contracts/slow_tree_contract/src/main.nr#L56-L58