Reading Data
Connecting to the Oracle
To use Tellor data, import usingTellor, our helper contract for any network, connect it to the Oracle, and read a value on your queryId
. This quickstart uses the BTC/USD SpotPrice
as an example query.
Installation
Importing
Just import the UsingTellor contract into your solidity file passing the desired Tellor address (see references page) as a parameter.
Line 7: Your constructor needs to specify the Tellor contract address (see references page for the address). For testing, use a TellorPlayground address. In production, use the Oracle address on your chosen network.
Reading data
Once we've created a queryId
, we're ready to add our Tellor data feed to our contract code. The best-practice for reading Tellor data is to use the function getDataBefore
. We use this function to leave time for disputes. In the example below, we'll add to the snippet above a function getBtcSpotPrice()
that reads the btc/usd price feed from the Oracle.
Line 16: Use usingtellor's getDataBefore(bytes32 _queryId, uint256 _timestamp) function with a buffer time (1 hour for example) to allow time for a bad value to be disputed
Addendum: Tellor Playground
Tellor Playground aims to help anyone building on Tellor to quickly bootstrap, implement, and test a Tellor integration. See the reference page for deployed addresses on various test networks.
The Playground is a simplified (and not a real oracle) Tellor, containing only the small bits that developers need to worry about: getting data, adding tips, reading events and so forth.
How to implement
Implementing the Playground is as simple as pointing the UsingTellor
constructor to the Playground on your network. See the reference page for deployed addresses on various test networks.
When finished testing with the Playground, switching back to the real Tellor only requires updating the oracle address in your UsingTellor implementation.
Last updated