Fetch Oracle
  • Welcome to Fetch
  • THE BASICS
    • What Problem Does Fetch Solve?
    • What Can You Do With Fetch?
    • The FETCH Token
    • Staking
    • Contracts Overview
    • Contract Addresses
    • Contributing
    • Audits
  • REPORTING DATA
    • How to Report Data
    • Requirements
      • (Optional) Using Cloud Hosting
    • Installing Telliot
      • Adding Accounts
      • MAC Virtual Machine with UTM
    • Reporting With Telliot
      • Reporting Options
      • Discord Notifications
    • Gas Fees
    • Add support for a new spot price
  • GETTING DATA
    • Tipping
    • Receiving Data From Fetch
    • Solidity
    • User Checklists
    • Testnet
    • Creating a Query
  • VOTES & DISPUTES
    • Voting
    • Disputing
    • Introduction to DVM
      • Installing DVM
      • Monitoring
  • OPTIONAL CONFIGS
    • Claim Tip Script ENV Config
  • Connect
    • Whitepaper
    • Telegram
    • Twitter/X
    • YouTube
Powered by GitBook
On this page
  • Getting a Query ID and Query Data
  • Creating a new Query Type
  • Example QueryData and QueryID
  • Next Steps
  1. GETTING DATA

Creating a Query

Tell the ecosystem what data you're seeking.

PreviousTestnetNextVoting

Last updated 9 months ago

All data reported to Fetch Oracle is associated with a unique QueryId and a timestamp.

When a user requests data using a and when a reporter submits data using submitValue, they have to input both the queryId and queryData.

The queryData tells reporters how to fulfill the data query, while also informing voters how to verify the data in a dispute. The queryId is defined as the keccak256 hash of the queryData field.

In order to query the Fetch oracle you'll need to first generate queryData and its hash, the queryId.

Getting a Query ID and Query Data

Use the tools below to generate a queryId and queryData:

Creating a new Query Type

To add a new data type to Fetch Oracle, you'll just need to define a new queryType. This is how you form a question so that Fetch Oracle reporters know exactly what data is being requested.

To create a new Query Type or specification for custom data you need from Fetch oracles, there are two options:

You'll need to determine three things: a unique queryType name, inputs, and outputs. So let's say you want a query for getting the price of any asset in any currency. In human-readable form, your question could look like this:

What is the price of PLS/USD?

You might formally define your query like this:

Name: SpotPrice

Inputs:

1. asset (string): Asset ID (e.g. PLS)

2. currency (string): Selected currency (e.g. USD)

Outputs:

1. price (uint256)

- abi_type: ufixed256x18 (18 decimals of precision)

- packed: false

First, put your question in queryData format, which means encoding your queryType name and arguments into bytes (see below). You'll then need to get a queryId, which is the bytes32 unique identifier for each Fetch Oracle data feed. The queryId is defined as the keccak256 hash of queryData. Once you know the queryId you'll be able to retrieve your data.

Example QueryData and QueryID

If you input pls and usd, respectively, the queryData would be:

0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706f745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003706c73000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000

and the queryId would be

0x83245f6a6a2f6458558a706270fbcc35ac3a81917602c1313d3bfa998dcc2d4b

Next Steps

You're free to build a query at any time and start integrating it into your project.

If the don't fit your needs, you can define a new one.

Fork the Fetch and make a pull request for a new Query type in ./types using .

Next, you may need to incentivize reporters to fetch the answer to your question. Check out the page to learn more.

Once Fetch Oracle reporters are submitting your new queryType on chain, you can retrieve your desired data with the help of , which is a helper contract that provides various Fetch Oracle data getters.

In Solidity, your contract can get data like .

When you reach the later stages of building your project, to Fetch Oracle's dataSpecs repository so that data reporters know how to fulfill your query.

For the best chance of success, it's a good idea to tip reporters by .

existing Query Types
DataSpecs repository
this template
Fill out this New Data Request Form
tipping
UsingFetch
this
add an issue
funding a feed
tip
Get A Query ID
Logo