Solidity Integration
To use Signum data, you can use the UsingTellor 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.
Installation
To install usingtellor, run one the following commands:
Hardhat:
Copy
Foundry:
Copy
Importing
To import the UsingTellor contract into your Solidity file, pass the desired Signum address (see the references page for the address) as a parameter:
Note: In the constructor on line 7, you need to specify the Signum contract address. For testing, you can use a Signum Playground address. In production, use the Oracle address on your chosen network.
Reading data
You can either use our QueryId Builder to create a queryId and hardcode it, or use solidity to generate it. Once you have created a queryId
, you can add the Signum data feed to your contract code.
The best practice for reading Signum data is to use the_getDataBefore
function with a buffer time that allows time for bad values to be disputed:
_getDataBefore(_queryId,
block.timestamp - 20 minutes
);
It's also best practice to require/check that the data is not too old. For example:
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:
Last updated