Prepaid Oracle User Guide

This guide provides step-by-step instructions for creating data requests to an external data provider API using the Prepaid Oracle system on the Canton blockchain.

circle-info

This document focuses on the request creation process using direct requests to the Canton JSON API.

Overview

The Prepaid Oracle system enables secure, paid requests for off-chain data through the Canton blockchain. The request creation process involves:

  1. Preparing request parameters: Gather and format the request payload.

  2. Retrieving contracts: Get the current Amulet rules and open mining round contracts.

  3. Exercising a contract choice: Submit a transaction that creates a paid data request.

The oracle then processes the request off-chain (including payment settlement) and posts the response back on-ledger.

Prerequisites

Required information

You need the following information before starting:

  • Canton participant endpoint: URL of your Canton participant JSON API

  • Canton authentication token: Valid token for API access

  • Consumer party ID: Your party identifier in Canton (e.g., Consumer::1220...)

  • RequestFactory contract ID: Contract ID for the request factory

  • DSO party ID: DSO party identifier

  • Data provider details (provider-dependent): Data request payload (stringified JSON)

  • Amulet contract ID: An Amulet contract to fund payment

  • Payment locked amount: Amount to lock for the request

Environment setup

Ensure you have:

  • A Canton node connected to the same domain as the oracle node

  • The Prepaid Oracle DAR uploaded to your Canton node

  • Sufficient Amulet balance for the request

Creating a Data Request

Prepare provider request parameters

Prepare the provider request payload as valid JSON, then stringify it (single-line JSON string).

Below is an example shape for a provider request payload. The exact schema depends on your data provider.

When sending the request to Canton, you will pass a stringified version of the JSON (quotes escaped, no unescaped newlines). Example:

Required parameters

The CreateRequest choice expects the following parameters:

  • dataRequest → Stringified provider request payload (stringified JSON)

  • lockedAmount → Amount to lock for payment

  • dso → The DSO party

  • amuletRulesCid → Current Amulet rules contract ID

  • openRoundCid → Current OpenMiningRound contract ID

  • inputs → A list of Amulets owned by your consumer party (typically one is enough)

Note: Parameter names are part of the on-ledger template interface. Even when switching data providers, the workflow stays the same; only the meaning/content of provider-specific fields (like catalog, dataRequest, and credentials) changes.

Submit the request creation transaction

Make a POST request to Canton to exercise the CreateRequest choice.

Request

Request body

Troubleshooting

A request can fail. In this case, the Request contract is archived and a FailedRequest is created. Common failure scenarios include:

Locked amount does not cover service amount

Cause: The lockedAmount you specified is less than the service fee charged by the oracle.

Solution: Increase lockedAmount and ensure you have sufficient Amulet balance.

Stringified JSON request data is not valid

Cause: dataRequest is not a properly stringified JSON string.

Solution: Validate and re-stringify your JSON:

  • Validate the JSON before stringifying.

  • Ensure all quotes are properly escaped.

  • Ensure newlines are removed or escaped (recommended: remove).

  • Test the final string with a JSON parser (it must parse as a JSON string whose content is valid JSON when decoded).

Provider returns an error when sending the request

Cause: The provider API returned an error when processing your request.

Solution: Check:

  • Request payload format and required fields for the provider schema.

  • Requested data is supported and you have permission.

  • Rate limits / throttling conditions.

  • Provider documentation for error codes and request schema.

Reading the FilledRequest

Request processing (what the oracle does)

After your request is created on-ledger, the oracle typically:

A FilledRequest contract will have fields similar to:

  • Detects your new request

  • Proceeds to payment by unlocking your Amulet, taking the service amount needed, and returning any remaining amount to the consumer party

  • Reads the Request contract

  • Makes the request to the data provider on your behalf

  • Updates the Request contract with status PENDING

  • Waits for the provider’s response to be available

  • Archives the pending Request and writes the response data into a FilledRequest

A FilledRequest contract will have fields similar to:

Read the FilledRequest contract

Once the oracle has processed your request and received a response, a FilledRequest contract is created. To retrieve it, query active contracts on the Canton ledger.

Query for FilledRequest contracts

Request

Request body

Expected response (example)

Understanding the FilledRequest fields

In createArgument, the key fields are:

  • oracle → The oracle party that processed the request

  • consumer → Your consumer party ID

  • requestData → The original request payload you submitted (stringified JSON)

  • responseData → The provider response payload (stringified JSON)

  • serviceAmountCharged → The actual service fee charged by the oracle

Service amount: serviceAmountCharged shows the fee deducted from your locked amount. Any remaining amount from lockedAmount is returned to you.

Last updated

Was this helpful?