How to Query Workers of Existing Topics Off-Chain

Querying workers of existing topics

Worker nodes invoke this function to gather inferences during inference solicitation

Querying Workers

There are workers today, mostly maintained by Upshot, that produce inferences for a set of existing topics. They can be queried for inferences via standard Blockless function calls, which in turn can be used today in on-chain applications via Allora adapter contracts. A Blockless function call can be submitted in a format like this:

curl --request POST \
  --url https://heads.testnet.allora.network/api/v1/functions/execute \
  --header 'accept: application/json, text/plain, */*' \
  --header 'content-type: application/json;charset=UTF-8' \
  --data '{
    "function_id": "bafybeigpiwl3o73zvvl6dxdqu7zqcub5mhg65jiky2xqb4rdhfmikswzqm",
    "method": "allora-inference-function.wasm",
    "parameters": null,
    "topic": "2",
    "config": {
        "env_vars": [
            {"name": "BLS_REQUEST_PATH", "value": "/api"},
            {"name": "ALLORA_ARG_PARAMS", "value": "yuga"}
        ],
        "number_of_nodes": -1,
        "timeout": 2
    }
}'

Let's break down this request body:

  • This request queries the index topic (topic 2).
  • We specify the function_id and method fields to indicate that we want to solicit inferences in a particular way (this concerns the internals of the worker nodes). These values can be recovered by following this step-by-step guide.
  • We pass in the input yuga to specify we want index levels for Yuga Labs NFT collections in particular. The workers that Upshot stood up actually can respond with index levels of a few different NFT indices, however, topic 5 only cares about Yuga Labs collections in particular, as specified in its metadata field.
  • number_of_nodes: -1 indicates that we don't care how many nodes respond, so long as they respond to roll call (opens in a new tab) within timeout: 2 seconds of the request broadcast.

Convenience Endpoint from Upshot

To conveniently relay inferences from worker nodes to developers, Upshot has created an endpoint to solicit inferences from worker nodes and merge them into a format compatible with our adapters. The output of this endpoint can be passed directly as-is to our adapter. To use this endpoint and obtain inferences, one can use the curl requests below, depending on the topic of interest. Note that the extra_data query parameter, where it is found, can be set to be any relevant argument of interest. extra_data is an arbitrary string that is hashed by our endpoint using keccak256 so that it is compatible with the extraData: bytes field of Allora adapter contracts.

Note that to use this endpoint you'll need an API key. To obtain an API key, you can create an account here (opens in a new tab).

Note

Finally, note that these inferences returned by either of the above means are "unsafe" in that they are not necessarily the same inferences that'll be used to update the weights of workers. Future iterations of Allora will address this particular vulnerability. Furthermore, "safe" inferences, which will be judged on-chain, can be queried directly on the Allora L1 via the commands GetInference and GetInferenceToScore in the Allora CLI.

ETH Price Projection, id=1

Request:

curl -X 'GET'  
  'https://api.upshot.xyz/v2/allora/adapter/ethereum-11155111?allora_topic_id=1&inference_value_type=uint256'  
  -H 'accept: application/json'   
  -H 'x-api-key: <YOUR_KEY_HERE>'

Example response:

{
    "request_id": "0429b690-2663-47a3-8a11-fa06e6ea87c1",
    "status": true,
    "data": {
        "signature": "0x5d170c31fcc2fc8e49655616ba99f6fd8ebd10a4d8c80ace1a6ea97d45ef715422a15c87b233b25e275aebe723ab50e802271f9e5ee0f92bfe21f64d57347dcb1b",
        "numeric_data": {
            "topic_id": "1",
            "numeric_values": [
                "3083922381062508000000"
            ],
            "timestamp": 1709225042,
            "extra_data": "0x"
        }
    }
}

Yuga Index Levels, id=2

Request:

curl -X 'GET'  
  'https://api.upshot.xyz/v2/allora/adapter/ethereum-11155111?allora_topic_id=2&inference_value_type=uint256'  
  -H 'accept: application/json'   
  -H 'x-api-key: <YOUR_KEY_HERE>'

Example response:

{
    "request_id": "2194de93-11bd-42cf-b541-267b6ec66c53",
    "status": true,
    "data": {
        "signature": "0xbe879f5fe7a6ea5d9162ac90e51330f3619f4854c4f36329891ee1f3e702854b7dc7ee01c1320dc87b0c933f4b0d1fb6c99861f4b1863b31ff1f783497ee61af1c",
        "numeric_data": {
            "topic_id": "2",
            "numeric_values": [
                "46071353120000000000"
            ],
            "timestamp": 1709224775,
            "extra_data": "0x"
        }
    }
}

NFT Appraisal, id=3

The extra_data field for Upshot nodes of this topic accepts NFT (721 or 1155) asset ids of the form <contract_address>/<token_id> e.g. 0x42069abfe407c60cf4ae4112bedead391dba1cdb/1465. Most popular PFP collections are supported by Upshot's models with minimal error bounds.

Request:

curl -X 'GET'  
  'https://api.upshot.xyz/v2/allora/adapter/ethereum-11155111?allora_topic_id=3&inference_value_type=uint256&extra_data=0x42069abfe407c60cf4ae4112bedead391dba1cdb%2F1465'  
  -H 'accept: application/json'  
  -H 'x-api-key: <YOUR_KEY_HERE>'

Example response:

{  
  "request_id": "d19a7dcb-7bc4-4696-bb32-3167a522e5fe",  
  "status": true,  
  "data": {  
    "signature": "0x3cb555eb498752d38f5efe03b38ac2b6f67bb0f1f1bb8d962b8ec1ceb3a229db7aa47966e75075f3dc44a4ca8857178e94308131d51fa363eb26f82d2b1cf3231c",  
    "numeric_data": {  
      "topic_id": "3",  
      "numeric_values": [  
        "786430000000000000"  
      ],  
      "timestamp": 1708065295,  
      "extra_data": "0x21aa590ce4bc64352998e94e3ff000981c9d3bdde4616983f6d3c3c8fd9e5159"  
    }  
  }  
}

Watches.io Appraisals, id=4

The extra_data field for Upshot nodes of this topic is the value of:

utils.keccak256(utils.solidityPack(
  ['address', 'uint256'],
  [contractAddress, tokenId]
))

contractAddress - watches wrapper NFT collection contract address
tokenId - watch NFT token id

Request:

curl --request 'GET' \
  "https://api.upshot.xyz/v2/allora/adapter/nft/ethereum-11155111?asset_id=0x75f9f22d1070fdd56bd1ddf2db4d65ab0f759431%2F23&allora_topic_id=4&inference_value_type=uint256" \
  -H 'accept: application/json' \
  -H 'x-api-key: <Your Upshot API key>'

Example response:

{
    "request_id": "ebbf46f9-162a-451d-9d61-b29068493270",
    "status": true,
    "data": {
        "signature": "0xdc3152b069249ade16d6e98dd5078c99d88999acee56558e746ddf4a9490e1ec322584b805d1dba4c2a3979fa7faf5e7176a0e2368900a6e2ed4f358111fd4ad1b",
        "numeric_data": {
            "topic_id": "4",
            "numeric_values": [
                "13409089411092726000000"
            ],
            "timestamp": 1709040705,
            "extra_data": "0x8730b88d28d6a481b2f0db59b73b83963bc5323cd009a27cf98e8b23203cf985"
        }
    }
}