Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

invoke

Invokes an external oracle process and returns its result.

Avoid calling this function directly in user code. Instead, write oracle interface modules, which group all single oracle features together.

To use an oracle, call invoke with:

  1. connection_string: A string describing how to connect to the oracle. The execution runtime handles oracle process management transparently under the hood. Consult your runtime documentation for details what protocols and options are supported. For wasm-based oracles, this is a path to a WASM binary that must be an asset.
  2. selector: The name or identifier of the method to invoke on the oracle (as a ByteArray). It acts as a function name or command within the oracle process.
  3. calldata: The arguments to pass to the oracle method, as a serializable Cairo type. To pass multiple arguments, use a tuple or struct that implements Serde.

The function returns a Result<R, oracle::Error>, where R is the expected return type, or an error if the invocation fails or the oracle returns an error.

mod math_oracle {
    pub type Result<T> = oracle::Result<T>;

    pub fn pow(x: u64, n: u32) -> Result<u128> {
        oracle::invoke("wasm:math_oracle.wasm", "pow", (x, n))
    }

    pub fn sqrt(x: u64) -> Result<u64> {
        oracle::invoke("wasm:math_oracle.wasm", "sqrt", x)
    }
}

Fully qualified path: oracle::invoke

pub fn invoke<T, +Destruct<T>, +Drop<T>, +Serde<T>, R, +Serde<R>>(
    connection_string: ByteArray, selector: ByteArray, calldata: T,
) -> Result<R, Error>