Links

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 Harmony.

The Price Feed Contracts

Mainnet

AAVE-USD: 0x6EE1EfCCe688D5B79CB8a400870AF471c5282992
BTC-USD: 0x3C41439Eb1bF3BA3b2C3f8C921088b267f8d11f4
ETH-USD: 0xbaf7C8149D586055ed02c286367A41E0aDA96b7C
LINK-USD: 0xD54F119D10901b4509610eA259A63169647800C4
ONE-USD: 0xdCD81FbbD6c4572A69a534D8b8152c562dA8AbEF
USDC-USD: 0xA45A41be2D8419B60A6CE2Bc393A0B086b8B3bda
USDT-USD: 0x5CaAeBE5C69a8287bffB9d00b5231bf7254145bf
UST-USD: 0xEF9ab2298715631dE7E8F17482ce63A108158819

Testnet

DAI-USD: 0x1FA508EB3Ac431f3a9e3958f2623358e07D50fe0
ETH-USD: 0x4f11696cE92D78165E1F8A9a4192444087a45b64
DSLA-USD: 0x5f0423B1a6935dc5596e7A24d98532b67A0AeFd8
USDC-USD: 0x6F2bD4158F771E120d3692C45Eb482C16f067dec
SUSHI-USD: 0x90142a6930ecF80F1d14943224C56CFe0CD0d347
USDT-USD: 0x9A37E1abFC430B9f5E204CA9294809c1AF37F697
WBTC-USD: 0xEF637736B220a58C661bfF4b71e03ca898DCC0Bd
BUSD-USD: 0xa0ABAcC3162430b67Aa6C135dfAA08E117A38bF0
ONE-USD: 0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD
LINK-USD: 0xcd11Ac8C18f3423c7a9C9d5784B580079A75E69a

Solidity

To consume price data, your smart contract should reference AggregatorV3Interface, which defines the external functions implemented by Price Feeds.
pragma solidity ^0.6.7;
​
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
​
contract PriceConsumerV3 {
​
AggregatorV3Interface internal priceFeed;
​
/**
* Network: Harmony testnet
* Aggregator: ONE/USD
* Address: 0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD
*/
constructor() public {
priceFeed = AggregatorV3Interface(0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD);
}
​
/**
* Returns the latest price
*/
function getThePrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}
​

Javascript

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

Python

from web3 import Web3
web3 = Web3(Web3.HTTPProvider('https://api.s0.b.hmny.io'))
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"}]'
addr = '0xcEe686F89bc0dABAd95AEAAC980aE1d97A075FAD'
contract = web3.eth.contract(address=addr, abi=abi)
latestData = contract.functions.latestRoundData().call()
print(latestData)
Last modified 11mo ago