Chainlink
This page explains how to get the latest price of ONE and other HRC20 assets inside smart contracts, using the Chainlink Price Feed on the Harmony testnet.

The Price Feed Contracts

1
DAI-USD: 0x1FA508EB3Ac431f3a9e3958f2623358e07D50fe0
2
ETH-USD: 0x4f11696cE92D78165E1F8A9a4192444087a45b64
3
DSLA-USD: 0x5f0423B1a6935dc5596e7A24d98532b67A0AeFd8
4
USDC-USD: 0x6F2bD4158F771E120d3692C45Eb482C16f067dec
5
SUSHI-USD: 0x90142a6930ecF80F1d14943224C56CFe0CD0d347
6
USDT-USD: 0x9A37E1abFC430B9f5E204CA9294809c1AF37F697
7
WBTC-USD: 0xEF637736B220a58C661bfF4b71e03ca898DCC0Bd
8
BUSD-USD: 0xa0ABAcC3162430b67Aa6C135dfAA08E117A38bF0
9
ONE-USD: 0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD
10
LINK-USD: 0xcd11Ac8C18f3423c7a9C9d5784B580079A75E69a
Copied!

Solidity

To consume price data, your smart contract should reference AggregatorV3Interface, which defines the external functions implemented by Price Feeds.
1
pragma solidity ^0.6.7;
2
3
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
4
5
contract PriceConsumerV3 {
6
7
AggregatorV3Interface internal priceFeed;
8
9
/**
10
* Network: Harmony testnet
11
* Aggregator: ONE/USD
12
* Address: 0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD
13
*/
14
constructor() public {
15
priceFeed = AggregatorV3Interface(0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD);
16
}
17
18
/**
19
* Returns the latest price
20
*/
21
function getThePrice() public view returns (int) {
22
(
23
uint80 roundID,
24
int price,
25
uint startedAt,
26
uint timeStamp,
27
uint80 answeredInRound
28
) = priceFeed.latestRoundData();
29
return price;
30
}
31
}
32
Copied!

Javascript

The latestRoundData function returns five values representing information about the latest price data. See Price Feeds API Reference for more details.
1
const web3 = new Web3("https://api.s0.b.hmny.io");
2
const aggregatorV3InterfaceABI = [{"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":[{"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":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}];
3
const addr = "0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD";
4
const priceFeed = new web3.eth.Contract(aggregatorV3InterfaceABI, addr);
5
priceFeed.methods.latestRoundData().call()
6
.then((roundData) => {
7
// Do something with roundData
8
console.log("Latest Round Data", roundData)
9
});
Copied!
Sample output when you run the above code:
1
Latest Round Data Result {
2
'0': '18446744073709552763',
3
'1': '11429419',
4
'2': '1629106535',
5
'3': '1629106535',
6
'4': '18446744073709552763',
7
roundId: '18446744073709552763',
8
answer: '11429419',
9
startedAt: '1629106535',
10
updatedAt: '1629106535',
11
answeredInRound: '18446744073709552763'
12
}
Copied!

Python

1
from web3 import Web3
2
web3 = Web3(Web3.HTTPProvider('https://api.s0.b.hmny.io'))
3
abi = '[{"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":[{"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":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]'
4
addr = '0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD'
5
contract = web3.eth.contract(address=addr, abi=abi)
6
latestData = contract.functions.latestRoundData().call()
7
print(latestData)
Copied!
Last modified 3mo ago