# Creating a Query

All data reported to Fetch Oracle is associated with a unique `QueryId` and a `timestamp`.&#x20;

When a user requests data using a [`tip`](https://docs.fetchoracle.com/getting-data/tipping) and when a reporter submits data using `submitValue`, they have to input both the `queryId` and `queryData`.&#x20;

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:`

{% embed url="<https://queryidbuilder.herokuapp.com/>" %}

{% embed url="<https://www.youtube.com/watch?index=2&list=PLuJHbmh0kCXVPHDA2Q3J3TfatBRGrOsm-&v=thjXi7FGLpU>" %}

{% hint style="info" %}
If the [existing Query Types](https://github.com/fetchoracle/dataSpecs/tree/main/types) don't fit your needs, you can define a new one.
{% endhint %}

## 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.&#x20;

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

* Fork the Fetch [DataSpecs repository](https://github.com/fetchoracle/dataSpecs) and make a pull request for a new Query type in `./types` using [this template](https://github.com/fetchoracle/dataSpecs/blob/main/types/_NewQueryTypeTemplate.md).
* [Fill out this New Data Request Form ](https://github.com/fetchoracle/dataSpecs/issues/new?assignees=\&labels=\&projects=\&template=new_query_type.yaml\&title=%5BNew+Data+Request+Form%5D%3A+)

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

Next, you may need to incentivize reporters to fetch the answer to your question.  Check out the [tipping ](https://docs.fetchoracle.com/getting-data/tipping)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 [UsingFetch](https://github.com/fetchoracle/usingfetch), which is a helper contract that provides various Fetch Oracle data getters.&#x20;

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.

In Solidity, your contract can get data like [this](https://docs.fetchoracle.com/getting-data/solidity).

### 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.&#x20;

When you reach the later stages of building your project, [add an issue](https://github.com/fetchoracle/dataSpecs/issues/new?assignees=\&labels=\&projects=\&template=new_query_type.yaml\&title=%5BNew+Data+Request+Form%5D%3A+) to Fetch Oracle's `dataSpecs` repository so that data reporters know how to fulfill your query. &#x20;

For the best chance of success, it's a good idea to tip reporters by [funding a feed](https://docs.fetchoracle.com/getting-data/tipping).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fetchoracle.com/getting-data/creating-a-query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
