Solidity

Learn how to set up solidity integration with Fetch Oracle.

Connecting to the Oracle

To use Fetch Oracle data, you can use the UsingFetcharrow-up-right helper contract. After connecting it to the oracle, you can read a value using your QueryId. This guide uses the PLS/USD SpotPrice as an example query.

Installation

To install usingfetch, run the following command:

npm install usingfetch

Importing

To import the UsingFetch contract into your Solidity file, pass the desired Fetch Oracle address (which can be found on the references page) as a parameter:

pragma solidity ^0.8.3;

import "usingfetch/contracts/UsingFetch.sol";

contract MyContract is UsingFetch {

  constructor(address payable _fetchAddress) UsingFetch(_fetchAddress) {

  }

  // ...

}
circle-info

Note: In the constructor, you need to specify the Fetch Oracle contract address. For testing, you can use a Fetch Oracle Playground address.

When working with live data, make sure to use the Fetch Oracle address on the PulseChain network.

Reading data

You can either use the QueryID builderarrow-up-right to create a QueryID and hardcode it, or use Solidity to generate it.

Once you have created a QueryID, you can add the Fetch Oracle data feed to your contract code.

triangle-exclamation

In the example below, we add a function getPlsSpotPrice that reads the PLS/USD price feed from the oracle:

Last updated