Solidity Integration
Last updated
Was this helpful?
Last updated
Was this helpful?
To use Tellor data, you can use the helper contract. After connecting it to the oracle, you can read a value using your queryId
. This guide uses the BTC/USD SpotPrice
as an example query.
To install usingtellor, run one the following commands:
Hardhat:
Foundry:
To import the UsingTellor contract into your Solidity file, pass the desired Tellor address (see the for the address) as a parameter:
_getDataBefore(_queryId,
block.timestamp - 20 minutes
);
require(block.timestamp -``
_timestampRetrieved < 24 hours
);
In the example below, we add a function getBtcSpotPrice
that reads the BTC/USD price feed from the Oracle:
Note: In the constructor on line 7, you need to specify the Tellor . For testing, you can use a Tellor Playground address. In production, use the Oracle address on your chosen network.
You can either use ourtoand hardcode it, or use solidity to generate it. Once you have created a queryId
, you can add the Tellor data feed to your contract code.
for reading Tellor data is to use the_getDataBefore
function with a buffer time that allows time for bad values to be disputed:
It's also best practice to require/ For example:
Next up! Please be sure to review the which guide you through the necessary preparations & processes for using the Tellor oracle