// SPDX-License-Identifier: MIT
import "usingtellor/contracts/UsingTellor.sol";
contract ExampleContract is UsingTellor {
// _tellorAddress is the address of the Tellor oracle
constructor(address payable _tellorAddress) UsingTellor(_tellorAddress) {}
function getBtcSpotPrice() external view returns(uint256) {
bytes memory _queryData = abi.encode("SpotPrice", abi.encode("btc", "usd"));
bytes32 _queryId = keccak256(_queryData);
// Tip: Use UsingTellor's getDataBefore(bytes32 _queryId, uint256 _timestamp)
// function with a buffer time (1 hour for example) to allow time for a bad value
(bool ifRetrieve, bytes memory _value, ) =
getDataBefore(_queryId, block.timestamp - 1 hours);
if (!ifRetrieve) return 0;
return _sliceUint(_value);
// All Tellor oracle values are stored in bytes format. If you need your data
// in uint256 format, you can parse bytes using a function like the one below
function _sliceUint(bytes memory _b) internal pure returns (uint256 _x) {
for (uint256 _i = 0; _i < _b.length; _i++) {
_number = _number * 2**8;
_number = _number + uint8(_b[_i]);