Oracles
ThunderCore oracle provides a series of asset prices on the chain to make your smart contract connect with real world.
For projects already integrated with Chainlink data feed , we are providing the same function interfaces to make your project cross-chain onto ThunderCore instantly.
Pending for Review
This is pre-release version section. Contents can be changed anytime, please use in your caution.

Get Started

You can get the latest contract interfaces and ABIs through npm:
1
$ npm install @thundercore/oracle
Copied!
or Yarn:
1
$ yarn add @thundercore/oracle
Copied!
And just a few lines of code, so you can get the latest price:
New project
Project integrated with Chainlink
Truffle (web3.js)
Hardhat (ethers.js)
1
import { FeedRegistryConsumerInterface } from '@thundercore/oracle/TTOracle.sol';
2
3
contract MyProject {
4
address public constant TT_ORACLE = 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE;
5
6
function getThunderTokenPrice() public view returns (int256) {
7
(
8
/* uint80 roundId */,
9
int256 answer,
10
/* uint256 startedAt */,
11
/* uint256 updatedAt */,
12
/* uint80 answeredInRound */
13
) = FeedRegistryConsumerInterface(TT_ORACLE)
14
.latestRoundData('TT/USDT');
15
16
return answer;
17
}
18
}
Copied!
1
import { FeedRegistryInterface } from "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol";
2
import { Denominations } from '@thundercore/oracle/TTOracle.sol';
3
4
contract MyProject {
5
address public constant TT_ORACLE = 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE;
6
7
function getThunderTokenPrice() public view returns (int256) {
8
(
9
/* uint80 roundId */,
10
int256 answer,
11
/* uint256 startedAt */,
12
/* uint256 updatedAt */,
13
/* uint80 answeredInRound */
14
) = FeedRegistryInterface(TT_ORACLE)
15
.latestRoundData(
16
Denominations.TT,
17
Denominations.USDT
18
);
19
20
return answer;
21
}
22
}
Copied!
1
# npm exec -- truffle console --network thundercore
2
# or
3
# yarn truffle console --network thundrcore
4
truffle(thundercore)> const abi = require('@thundercore/oracle/abi/FeedRegistryConsumerInterface.json')
5
6
truffle(thundercore)> const oracle = new web3.eth.Contract(abi, TT_ORACLE)
7
8
truffle(thundercore)> oracle.methods.latestRoundData('TT/USDT').call().then(res => res.answer).then(web3.utils.fromWei)
9
'0.01663655'
Copied!
1
# npm exec -- hardhat console --network thundercore
2
# or
3
# yarn truffle console --network thundrcore
4
> const abi = require('@thundercore/oracle/abi/FeedRegistryConsumerInterface.json')
5
6
> const oracle = new hre.ethers.Contract(TT_ORACLE, abi, hre.ethers.provider)
7
8
> await oracle.latestRoundData('TT/USDT').then(res => res.answer).then(hre.ethers.utils.formatEther)
9
'0.01663655'
Copied!
You can try it on ThunderCore testnet:
ThunderCore Testnet Oracle Example

Using Data Feeds

Data Feeds are the quickest way to connect with the real-world asset prices.
Feed Registry
You can use the Feed Registry to reference data feed assets by pair name or currency identifier.

Solidity

To consume price data, your smart contract should reference DataFeedConsumerInterface, which defines the external functions implemented by Data Feeds.
If you've applied Chainlink aggregator in your service, i.e. AggregatorInterface, AggregatorV3Interface, or AggregatorV2V3Interface, you don't have to change the interface. The only difference is the feed address, just change it and test the result on the fly.
1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8;
3
4
import { DataFeedConsumerInterface } from "@thundercore/oracle/TTOracle.sol";
5
6
contract PriceConsumer {
7
8
DataFeedConsumerInterface internal priceFeed;
9
10
/**
11
* Network: ThunderCore testnet [18]
12
* Pair: TT/USDT
13
* Address: 0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c
14
*/
15
constructor() {
16
priceFeed = DataFeedConsumerInterface(0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c);
17
}
18
19
/**
20
* Returns the latest price
21
*/
22
function getLatestPrice() public view returns (int256) {
23
(
24
/* uint80 roundID */,
25
int256 price,
26
/* uint256 startedAt */,
27
/* uint256 updatedAt */,
28
/* uint80 answeredInRound */
29
) = priceFeed.latestRoundData();
30
31
return price;
32
}
33
}
Copied!
The latestRoundData function returns five values representing information about the latest price data. See the Data Feeds API Reference for more details.

ECMAScript (JavaScript)

web3.js (Node.js)
ethers.js (Node.js)
1
const Web3 = require('web3')
2
const web3 = new Web3('https://testnet-rpc.thundercore.com')
3
const abi = require('@thundercore/oracle/abi/DataFeedConsumerInterface.json')
4
const address = '0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c'
5
const priceFeed = new web3.eth.Contract(abi, address)
6
7
priceFeed.methods.latestRoundData().call()
8
.then(res => res.answer)
9
.then(web3.utils.fromWei)
10
.then((price) => { console.log(price) })
Copied!
1
const { ethers } = require('ethers')
2
const provider = new ethers.providers.JsonRpcProvider('https://testnet-rpc.thundercore.com')
3
const abi = require('@thundercore/oracle/abi/DataFeedConsumerInterface.json')
4
const address = '0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c'
5
const priceFeed = new ethers.Contract(address, abi, provider)
6
7
priceFeed.latestRoundData()
8
.then(({ answer }) => { console.log(ethers.utils.formatEther(answer)) })
Copied!

Python

This example uses Web3.py to retrieve feed data from the TT/USDT feed on the ThunderCore testnet network.
1
from web3 import Web3
2
web3 = Web3(Web3.HTTPProvider('https://testnet-rpc.thundercore.com'))
3
abi = '[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int256","name":"current","type":"int256"},{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"}],"name":"AnswerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":true,"internalType":"address","name":"startedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"}],"name":"NewRound","type":"event"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"hasRoundData","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"getPreviousRoundId","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"getNextRoundId","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"}]'
4
addr = '0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c'
5
contract = web3.eth.contract(address=addr, abi=abi)
6
latestData = contract.functions.latestRoundData().call()
7
print(latestData)
Copied!

Getting a different price denomination

If you require a denomination other than what we have provided, you can use two data feeds to derive the pair that you need. For example, if you need a TT/ETH price, you could take the TT/USDT feed and the ETH/USDT feed and derive TT/ETH using division.
TT/USDTETH/USDT=TT/USDTETH/USDT=TT/ETH\frac{TT / USDT}{ETH / USDT} = \frac{TT / \sout{USDT}}{ETH / \sout{USDT}} = TT / ETH

Historical Price Data

The most common use case for data feeds is to get the latest price. However, we also exposes functions which can be used to retrieve price data of a previous round ID.
Never over rely on previous round data of oracle
If your project requires price before one week or longer ago, always store those prices inside your smart contract.
In ThunderCore oracle, we guarantee to keeps one recent week prices. And after one week, those data could be purged anytime.

Solidity

1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8;
3
4
import { DataFeedConsumerInterface } from "@thundercore/oracle/TTOracle.sol";
5
6
contract HistoricalPriceConsumer {
7
8
DataFeedConsumerInterface internal priceFeed;
9
10
/**
11
* Network: ThunderCore testnet [18]
12
* Pair: TT/USDT
13
* Address: 0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c
14
*/
15
constructor() {
16
priceFeed = DataFeedConsumerInterface(0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c);
17
}
18
19
/**
20
* Returns historical price for a round id
21
*/
22
function getHistoricalPrice(uint80 roundId) public view returns (int256) {
23
require(priceFeed.hasRoundData(roundId), 'No this round data');
24
25
(
26
/* uint80 roundID */,
27
int256 price,
28
/* uint256 startedAt */,
29
/* uint256 updatedAt */,
30
/* uint80 answeredInRound */
31
) = priceFeed.getRoundData(roundId);
32
33
return price;
34
}
35
}
Copied!

ECMAScript (JavaScript)

web3.js (Node.js)
ethers.js (Node.js)
1
const Web3 = require('web3')
2
const web3 = new Web3('https://testnet-rpc.thundercore.com')
3
const abi = require('@thundercore/oracle/abi/DataFeedConsumerInterface.json')
4
const address = '0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c'
5
const priceFeed = new web3.eth.Contract(abi, address)
6
7
priceFeed.methods.getRoundData(1).call()
8
.then(res => res.answer)
9
.then(web3.utils.fromWei)
10
.then((price) => { console.log(price) })
Copied!
1
const { ethers } = require('ethers')
2
const provider = new ethers.providers.JsonRpcProvider('https://testnet-rpc.thundercore.com')
3
const abi = require('@thundercore/oracle/abi/DataFeedConsumerInterface.json')
4
const address = '0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c'
5
const priceFeed = new ethers.Contract(address, abi, provider)
6
7
priceFeed.getRoundData(1)
8
.then(({ answer }) => { console.log(ethers.utils.formatEther(answer)) })
Copied!

Python

1
from web3 import Web3
2
web3 = Web3(Web3.HTTPProvider('https://testnet-rpc.thundercore.com'))
3
abi = '[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int256","name":"current","type":"int256"},{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"}],"name":"AnswerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"roundId","type":"uint256"},{"indexed":true,"internalType":"address","name":"startedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"}],"name":"NewRound","type":"event"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"hasRoundData","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"getPreviousRoundId","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"getNextRoundId","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"}]'
4
addr = '0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c'
5
contract = web3.eth.contract(address=addr, abi=abi)
6
roundData = contract.functions.getRoundData(1).call()
7
print(roundData)
Copied!

Feed Registry

The Feed Registry is an on-chain mapping of assets to feeds. It enables you to query data feeds from asset addresses directly, without needing to know the feed contract addresses.

Base and Quote

You are free to choose querying feeds from their pair names, e.g. TT/USDT; or you can keep Chainlink style by token addresses.
Query by pair name
Query by address
1
registry.latestRoundData('TT/USDT');
Copied!
1
registry.latestRoundData(
2
Denominations.TT,
3
Denominations.USDT
4
);
Copied!

Solidity example code

1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8;
3
4
import { FeedRegistryInterface } from '@thundercore/oracle/TTOracle.sol';
5
6
contract PriceConsumer {
7
FeedRegistryInterface internal registry;
8
9
/**
10
* Network: ThunderCore testnet
11
* Feed Registry: 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE
12
*/
13
constructor(address _registry) {
14
registry = FeedRegistryInterface(_registry);
15
}
16
17
/**
18
* Returns the TT / USDT price
19
*/
20
function getTTPrice() public view returns (int) {
21
(
22
uint80 roundID,
23
int256 price,
24
uint256 startedAt,
25
uint256 timeStamp,
26
uint80 answeredInRound
27
) = registry.latestRoundData('TT/USDT');
28
return price;
29
}
30
}
Copied!

ECMAScript (JavaScript) example

1
const Web3 = require('web3')
2
const web3 = new Web3('https://testnet-rpc.thundercore.com')
3
const abi = require('@thundercore/oracle/abi/FeedRegistryConsumerInterface.json')
4
const address = '0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE'
5
const registry = new web3.eth.Contract(abi, address)
6
7
registry.methods.latestRoundData('TT/USDT').call()
8
.then(res => res.answer)
9
.then(web3.utils.fromWei)
10
.then((price) => { console.log(price) })
Copied!

API Reference

API reference for DataFeedConsumerInterface.
Name
Description
decimals
Decimals of "answer" in responsed round data
Feed pair name, format "${BASE}/${QUOTE}"
version
The code version of the feed proxy points to
Check if the round data existed
Get data from a specific round
Get data from the latest round
Get previous data existed round ID
Get next data existed round ID

decimals

Get the decimals of "answer" in responsed round data
1
function decimals() external view returns (uint8)
Copied!
  • RETURN: The number of decimals.

description

Get the feed pair name, format "${BASE}/${QUOTE}"
1
function description() external view returns (string memory);
Copied!
  • RETURN: The pair name of data feed.

version

Get the code version of the feed proxy points to
1
function version() external view returns (uint256);
Copied!
  • RETURN: The code version.

hasRoundData

Check if the round data existed
1
function hasRoundData(uint80 roundId) external view returns (bool);
Copied!
  • Petermeters
    • roundId: The round ID to check if round data existed in data feed.
  • Return Values
    • RETURN: Round data exists or not.

getRoundData

Get data from a specific round
1
function getRoundData(uint80 _roundId)
2
external
3
view
4
returns (
5
uint80 roundId,
6
int256 answer,
7
uint256 startedAt,
8
uint256 updatedAt,
9
uint80 answeredInRound
10
);
Copied!
  • Petermeters
    • roundId: The round ID
  • Return Values
    • roundId: The round ID.
    • answer: The price.
    • startedAt: Timestamp of when the round started.
    • updatedAt: Timestamp of when the round was last updated.
    • answeredInRound: The round ID of the round in which the answer was computed.

latestRoundData

Get data from the latest round
1
function latestRoundData()
2
external
3
view
4
returns (
5
uint80 roundId,
6
int256 answer,
7
uint256 startedAt,
8
uint256 updatedAt,
9
uint80 answeredInRound
10
);
Copied!
  • Return Values
    • roundId: The round ID.
    • answer: The price.
    • startedAt: Timestamp of when the round started.
    • updatedAt: Timestamp of when the round was last updated.
    • answeredInRound: The round ID of the round in which the answer was computed.

getPreviousRoundId

Get previous data existed round ID
1
function getPreviousRoundId(uint80 roundId) external view returns (uint80);
Copied!
  • Petermeters
    • roundId: The round ID to look up closest previous valid round ID.
  • Return Values
    • RETURN: The previous valid round ID to parameter specified round ID; return 0 if no valid round ID before.

getNextRoundId

Get next data existed round ID
1
function getNextRoundId(uint80 roundId) external view returns (uint80);
Copied!
  • Petermeters
    • roundId: The round ID to look up closest next valid round ID.
  • Return Values
    • RETURN: The next valid round ID to parameter specified round ID; return 0 if no valid round ID after.

Contract Addresses

ThunderCore mainnet (108)
ThunderCore testnet (18)
FeedRegistry: 0x70B3B30066b4F7B927f26C408461b3F176AA07Dc
Pair
Dec
Proxy
TT/USDT
18
0x0808Ac0b6f4B502C59e40D147dDA7Bfa1AE7BD6C
ETH/USDT
18
0x1Cc8dE741C6d32c321B46a23D8289F337aBEf4D9
WBTC/USDT
18
0x632Ce66C7C973eE2662F207cBbA04A6E2d9B91bb
BNB/USDT
18
0xFB19d0dC0194A99913Daaa3d11f8d00ff4affa81
HT/USDT
18
0x53BD5eB3fF53F19F1eD7871D48B200f3312E8017
FeedRegistry: 0xD477d4d8132C6fce38f0bf38f46FcB62D6c5ddaE
Pair
Dec
Proxy
TT/USDT
18
0x1Ce18a95C56Db619C070AeF58918EaB09FE2634c
ETH/USDT
18
0x555Ad57b0EA33e2ac49D267C96eF98aa254a54c4
WBTC/USDT
18
0x83Ac10Bc6dC02E07c71dfBF45ca7355675D340B5
BNB/USDT
18
0xcE6bd682263F58e1e2828ccA5AEc6A671FFfd739
HT/USDT
18
0xB6FEB586A86b4C542295E1232B45DE5F80961a16