Band Oracle (legacy testnet example)

Legacy BandChain devnet bridge example retained for historical context; not for new production integrations.

This legacy page documented an earlier integration between TRON and Band's decentralized oracle infrastructure. It does not describe the current Band product or a currently supported TRON deployment.

⚠️

Legacy testnet example

This page describes an earlier BandChain devnet bridge and is retained for historical context. The referenced devnet explorer and its generated helper contracts are no longer available. Do not use the address, oracle script ID, or helper files below for a new production integration; consult the current Band documentation and verify current network support and contract addresses first.

The Bridge Contract

Bridge Architecture

In this retired example, applications read Band oracle data through a bridge contract that was deployed on a former TRON testnet at address TPxsemS7h9rrJPZAPDjP7rmLoA4ErYny69. Do not assume that this address or deployment is still available.

The historical price data originated from requests on BandChain. Values were calculated from results retrieved by validators from CoinGecko, CryptoCompare, TRON, and Alpha Vantage APIs through a price-aggregator oracle script on the retired devnet.

The bridge contract then retrieved and stored those request results in contract state.

Data Available (Testnet)

The retired bridge stored the following price pairs, whose values were updated every five minutes at the time this example was active:

Cryptocurrency Prices (CoinGecko, CryptoCompare, Binance, Binance US):

  • BTC/USD
  • ETH/USD
  • TRX/USD
  • BAND/USD

Commodity Prices (Alpha Vantage):

  • XAU/USD
  • XAG/USD

Foreign Exchange Conversion Rates (Alpha Vantage):

  • EUR/USD
  • CNY/USD
  • JPY/USD
  • GBP/USD
  • KRW/USD

In addition to each price value, the bridge exposed the following information:

  • The multiplier used to calculate the stored price value
  • The timestamp of when the specific price request was resolved on BandChain

These fields were intended to help consumers validate the returned data.

Bridge Contract Price Update Process

The Band Foundation maintained this bridge while the example was active. Plans stated in the original page to publish additional guides are historical and must not be treated as a current roadmap.

Retrieving and Using the Price Data

The following non-runnable code is preserved only to illustrate how the retired bridge was consumed.

pragma solidity 0.5.9;
pragma experimental ABIEncoderV2;

import "./Obi.sol";
import {IBridge, IBridgeCache} from "./IBridgeWithCache.sol";
import {ParamsDecoder, ResultDecoder} from "./Decoders.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";


contract SimplePriceDB {
    using SafeMath for uint256;
    using ResultDecoder for bytes;
    using ParamsDecoder for bytes;
    
    IBridgeCache public bridge;
    IBridge.RequestPacket public req;
    
    uint256 public current_price;

    constructor(IBridgeCache bridge_) public {
        bridge = bridge_;
        
        req.clientId = "tron_testnet";
        req.oracleScriptId = 76;
        // {symbol:"BTC"}
        req.params = hex"00000003425443";
        req.askCount = 4;
        req.minCount = 3;
    }

    // Fetches the latest BTC/USD price value from the bridge contract and saves it to state.
    function setPrice() public {
        IBridge.ResponsePacket memory res = bridge.getLatestResponse(req);
        ResultDecoder.Result memory result = res.result.decodeResult();
        current_price = result.px;
    }
}

The remaining sections explain the historical code structure.

Imports

import "./Obi.sol";
import {IBridge} from "./IBridgeWithCache.sol";
import {ParamsDecoder, ResultDecoder} from "./Decoders.sol";
import "openzeppelin-solidity/contracts/math/SafeMath.sol";

Aside from SafeMath.sol, the historical contract required three Band-specific helper files: Obi.sol, Decoders.sol, and IBridgeWithCache.sol.

Obi.sol
This file contained functions for serializing and deserializing binary data in the legacy integration. The historical specification is available on the wiki, and the corresponding code remains in the BandChain repository.

Decoders.sol
This generated helper was used to decode the response format of legacy oracle script 76. Its original devnet explorer download is no longer available, so the example is not copy-paste runnable. For a new integration, obtain the decoder and interface specified by the current Band developer documentation rather than reconstructing this retired artifact.

IBridgeWithCache.sol
This was the interface file for the retired bridge contract.

Contract

contract SimplePriceDB {
    using SafeMath for uint256;
    using ResultDecoder for bytes;
    using ParamsDecoder for bytes;
    
    IBridgeCache public bridge;
    IBridge.RequestPacket public req;
    
    uint256 public current_price;

    constructor(IBridgeCache bridge_) public {
        bridge = bridge_;
        
        req.clientId = "tron_testnet";
        req.oracleScriptId = 76;
        // {symbol:"BTC"}
        req.params = hex"00000003425443";
        req.askCount = 4;
        req.minCount = 3;
    }

    // Fetches the latest BTC/USD price value from the bridge contract and saves it to state.
    function setPrice() public {
        IBridge.ResponsePacket memory res = bridge.getLatestResponse(req);
        ResultDecoder.Result memory result = res.result.decodeResult();
        current_price = result.px;
    }
}

The historical contract had two main parts: its constructor and the setPrice function.

Contract Constructor

constructor(IBridge bridge_) public {
    bridge = bridge_;

    req.clientId = "tron_testnet";
    req.oracleScriptId = 76;
    // {symbol:"BTC"}
    req.params = hex"00000003425443";
    req.askCount = 4;
    req.minCount = 3;
}

The constructor took the bridge address and populated the req (RequestPacket) fields used to retrieve a price in this retired example:

  • clientId ("tron_testnet"): the unique identifier of this oracle request, as specified by the client.
  • oracleScriptId (76): The unique identifier number assigned to the oracle script when it was first registered on Bandchain.
  • params (hex"00000003425443"): The data passed over to the oracle script for the script to use during its execution. In this case, it is the hex representation of the OBI-encoded request struct{"symbol":"BTC"}.
  • minCount (3): The minimum number of validators necessary for the request to proceed to the execution phase. Therefore, the minCount value must be less than or equal to the askCount.
  • askCount (4): The number of validators that are requested to respond to this request.

The specific params for each of the available price pairs are:

PairParams
BTC/USDhex"00000003425443"
ETH/USDhex"00000003455448"
TRX/USDhex"00000003545258"
BAND/USDhex"0000000442414e44"
XAU/USDhex"00000003584155"
XAG/USDhex"00000003584147"
EUR/USDhex"00000003455552"
CNY/USDhex"00000003434e59"
JPY/USDhex"000000034a5059"
GBP/USDhex"00000003474250"
KRW/USDhex"000000034b5257"

setPrice Function

// Fetches the latest BTC/USD price value from the bridge contract and saves it to state.
function setPrice() public {
    IBridge.ResponsePacket memory res = bridge.getLatestResponse(req);
    ResultDecoder.Result memory result = res.result.decodeResult();
    current_price = result.px;
}

In the historical flow, this function called getLatestResponse for a BTC/USD request, decoded the response with Decoders.sol, and saved the result in contract state. It is not a current integration example.