Canton pull oracle

circle-info

This guide provides step-by-step instructions for publishing BTC-USD price data to the Canton blockchain using the pull oracle system. The guide assumes that the MasterOracle and FeedEntitlement contracts already exist and focuses on the publication process using generic HTTP requests.

Overview

The pull oracle system enables secure publication of real-time cryptocurrency market data from Kaiko API to the Canton blockchain. The publication process involves:

  1. Fetching market data: Retrieve signed price data from Kaiko API

  2. Contract exercise: Submit transaction to publish data on blockchain

The pull oracle workflow has two phases: publish and verify. In the publish phase, the client fetches a Kaiko-signed BTC‑USD observation (value, timestamp, signature) from the Kaiko Market API and submits it to Canton by exercising PublishSignedData on the on-chain MasterOracle contract. The ledger then validates the signature against the oracle key and enforces the caller’s FeedEntitlement; only if both checks pass is a new PublishedSignedData state created on-chain. In the verify phase, any consumer can read the on-chain PublishedSignedData (e.g., via ExtractDataFields) to retrieve the stored fields and rely on the fact that they were accepted only after on-chain verification.

Prerequisites

Required information

You need the following information before starting:

  • Canton participant endpoint: URL of your Canton participant

  • Canton authentication token: Valid JWT token for API access

  • Kaiko API key: Valid API key for accessing Kaiko market data

  • Actor Party ID: Your party identifier in Canton (e.g., PO1-DataProvider::1220...)

  • FeedEntitlement Contract ID: Contract ID for your data feed entitlement

Environment setup

Set up your environment configuration by copying scripts/.env.sample to scripts/.env and filling the required values

Ensure you have:

  • HTTP client capability (curl, fetch, requests library, etc.)

  • JSON parsing capability

  • Hex encoding/decoding capability

Upload the dar file to your ledger

Publishing BTC-USD price data

Step 1: Fetch market data from Kaiko API

Make a GET request to retrieve the latest BTC-USD price data with cryptographic signature.

The price source can be chosen between:

Request:

Expected Response:

Extract Required Fields:

  • data.name → feedId (e.g., "btc-usd")

  • data.value → price value (e.g., 67850123456)

  • data.decimal → decimal places (e.g., 6)

  • data.timestamp → Unix timestamp in milliseconds

  • data.signature → Cryptographic signature from Kaiko

  • canton_oracle.* → Disclosed contract information

Step 2: Submit Publication Transaction

Make a POST request to Canton to exercise the PublishSignedData choice:

Request:

Request body:

Troubleshooting

Common error responses

Signature validation failed

  • Error: "Signature validation failed"

  • Cause: Invalid signature or hash mismatch

  • Solution:

    • Ensure signature is DER-encoded secp256k1

    • Verify hash calculation matches exactly

    • Check that signature was generated with correct private key

Feed not authorized

  • Error: "Feed not authorized"

  • Cause: FeedEntitlement doesn't include "btc-usd" feed

  • Solution: Verify your entitlement contract authorizes the btc-usd feed

Contract not visible

  • Error: "Contract not visible"

  • Cause: Actor party cannot see the contracts

  • Solution:

    • Verify party IDs are correct

    • Ensure contracts exist and are active

    • Check party has proper access permissions

Debugging steps

Verify API response:

Test canton connection

Check contract status

Advanced examples

Complete implementation example (Python)

Reference data

Required contract IDs

Replace these with your actual contract IDs:

Contract Type
Example ID
Description

MasterOracle (BTC-USD)

00b59a8e38e273...

Validates BTC-USD signatures

FeedEntitlement

00f6b5eff282ce...

Authorizes your party for BTC-USD

API Endpoints

Service
Endpoint
Purpose

Kaiko API

https://us.market-api.kaiko.io/v2/data/canton/oracle/price/btc-usd

Fetch signed price data

Canton API

PARTICIPANT_JSON_API_URL/v2/commands/submit-and-wait

Submit transactions

Canton Health

PARTICIPANT_JSON_API_URL/v2/health

Check API status


PublishedSignedData on-chain reading

Here is a template example for a contract that would read the values of an on-chain PublishedSignedData instance by using the PublishedData interface of the Kaiko data standard that PublishedSignedData implements. You can find this example project in resources/example.

Exercising ExtractDataFields choice

To extract the core data fields (feedId, value, decimal, timestamp) from a published data contract, use the following HTTP request:

Request:

Request body:

Expected response

Response fields

_1

feedId (string)

The feed identifier, e.g., "btc-usd"

_2

value (string)

The price value as a string representation, e.g., "108542709812"

_3

decimal (string)

Number of decimal places, e.g., "6"

_4

timestamp (string)

Unix timestamp in milliseconds, e.g., "1761148541270"

The extracted values show that the BTC-USD price was 108,542.709812 (108542709812 with 6 decimal places) at timestamp 1761148541270.

Last updated

Was this helpful?