Oraichain
  • ORAICHAIN
    • Introduction
    • System Overview
      • AI Layer 1 for Data Economy & blockchain oracle services
      • Layer 2 Rollups and Subnetworks
      • Verifiable and trustless AI Execution
      • Protocol Messages
      • IBC Integration
    • Use Cases
    • Token Economics
  • DEVELOPER GUIDES
    • General
      • Blockchain details
    • CosmWasm Contracts
      • Compile a Contract
      • Deploy a Contract
      • Query a Contract
      • Send tokens to a Contract
      • Manage Contracts using design patterns
      • End-to-end CosmWasm testing with CW-simulate
    • Local testnet chain
    • Wallet
      • OWallet
    • Price Feed
      • CW Oracle Hub
    • VRF 2.0
      • Introduction to Oraichain VRF 2.0
      • Get a Random Value from API
        • Get VRF Value from different networks
        • Contract Addresses and Pricing
        • Validate a Group Signature
      • Security Remarks
      • API Reference
      • Get support from Oraichain team
    • OraiDEX
      • ORAIX Token
      • OBridge
        • OraiBTC
        • TON Bridge
          • TON Blockchain 101
      • Decentralization
    • Indexers
      • SubQuery
    • OraichainEVM
      • Getting started
      • Smart Contracts
        • Oraichain EVM Precompiled Contracts
        • Address
        • Bank
        • Wasm
        • Authz
      • Guides
        • Metamask
        • Remix
        • Foundry
        • Hardhat
        • Tools
        • Oraichain EVM RPC
  • GOVERNANCE
    • Privacy Policy
  • NODES & VALIDATORS
    • Networks
      • Joining Mainnet
        • Build Linux binary from source and become a Sentry Node Operator
        • Become a Validator
      • Joining Testnet
        • Become Testnet Fullnode From Source
        • StateSync Testnet
        • Faucet Testnet
    • Oraichain Tutorials
      • Migrate one Oraichain node to another
      • Cosmovisor
      • Update validator image
      • Tenderduty
      • Grafana
      • Tracking Unvoted Proposals
      • Tmtop
Powered by GitBook
On this page
  • Introduction
  • How It Works
  • Core Components
  • Data Flow
  • Integration with Smart Contracts
  • Benefits
  • Use Cases

Was this helpful?

Edit on GitHub
  1. DEVELOPER GUIDES
  2. Price Feed

CW Oracle Hub

Introduction

The CW Oracle Hub is a crucial component of the Oraichain ecosystem that enables smart contracts to securely access and validate external data sources, particularly AI APIs. It serves as a bridge between blockchain smart contracts and off-chain data, ensuring data reliability and security through a decentralized validation mechanism.

How It Works

Core Components

  1. Price Feed Contract

    • Manages and stores price data from various sources

    • Handles price updates and validation

    • Provides query interfaces for smart contracts to access price data

  2. Validator Network

    • Validators collect and verify data from external sources

    • Execute test cases to ensure data quality

    • Participate in consensus for data validation

  3. Test Case System

    • Allows users to define test cases for data validation

    • Ensures data quality and reliability

    • Provides flexibility in validation requirements

Data Flow

  1. Request Initiation

    • Smart contracts or users initiate data requests

    • Specify required data sources and test cases

    • Set validation parameters

  2. Data Collection

    • Validators fetch data from specified sources

    • Execute test cases on the collected data

    • Validate data against predefined criteria

  3. Consensus & Storage

    • Validators reach consensus on data validity

    • Validated data is stored on-chain

    • Results are made available to requesting contracts

Integration with Smart Contracts

To integrate with the CW Oracle Hub, smart contracts need to:

  1. Set the CW Oracle Hub address as admin

  2. Implement the required message types

  3. Handle price feed updates

Example integration:

// msg.rs
#[cw_serde]
pub enum SudoMsg {
    AppendPrice {
        key: String,
        price: Uint128,
        timestamp: u64,
    },
}

// contract.rs
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(deps: DepsMut, _env: Env, msg: SudoMsg) -> Result<Response, ContractError> {
    match msg {
        ExecuteMsg::AppendPrice {
            key,
            price,
            timestamp,
        } => append_price(deps, info, key, price, timestamp),
    }
}

Benefits

  1. Decentralized Validation

    • Multiple validators ensure data reliability

    • No single point of failure

    • Transparent validation process

  2. Flexible Testing

    • Customizable test cases

    • Quality assurance for data sources

    • Adaptable to different use cases

  3. Secure Integration

    • Trustless data access

    • On-chain verification

    • Protected against data manipulation

Use Cases

The CW Oracle Hub is particularly useful for:

  1. DeFi Applications

    • Price feeds for trading

    • Asset valuation

    • Market data integration

  2. AI Services

    • AI model outputs validation

    • Machine learning predictions

    • Data quality assurance

  3. Cross-chain Applications

    • Multi-chain data synchronization

    • Cross-chain price feeds

    • Interoperable data access

PreviousPrice FeedNextVRF 2.0

Last updated 1 month ago

Was this helpful?