Discover the World of datatokens: Retrieving a List of datatokens
With your newfound knowledge of fetching data NFTs and retrieving the associated information, fetching a list of datatokens will be a breeze 🌊. Building upon your understanding, let's now delve into the process of retrieving a list of datatokens. By applying similar techniques and leveraging the power of GraphQL queries, you'll be able to effortlessly navigate the landscape of datatokens and access the wealth of information they hold. So, let's dive right in and unlock the potential of exploring datatokens with ease and efficiency.
PS: In this example, the query is executed on the Ocean subgraph deployed on the mainnet. If you want to change the network, please refer tothis table.
The javascript below can be used to run the query. If you wish to change the network, replace the variable's value network as needed.
The Python script below can be used to run the query and fetch a list of datatokens. If you wish to change the network, then replace the value of the variable base_url as needed.
Create script
list_all_tokens.py
import requests
import json
query = """
{{
tokens(skip:0, first: 2, subgraphError: deny){{
id
symbol
nft {{
name
symbol
address
}}
name
symbol
cap
isDatatoken
holderCount
orderCount
orders(skip:0,first:1){{
amount
serviceIndex
payer {{
id
}}
consumer{{
id
}}
estimatedUSDValue
lastPriceToken
lastPriceValue
}}
}}
}}"""
base_url = "https://v4.subgraph.mainnet.oceanprotocol.com"
route = "/subgraphs/name/oceanprotocol/ocean-subgraph"
url = base_url + route
headers = {"Content-Type": "application/json"}
payload = json.dumps({"query": query})
response = requests.request("POST", url, headers=headers, data=payload)
result = json.loads(response.text)
print(json.dumps(result, indent=4, sort_keys=True))
Execute script
python list_all_tokens.py
Copy the query to fetch a list of datatokens in the Ocean Subgraph GraphiQL interface.
{
tokens(skip:0, first: 2, subgraphError: deny){
id
symbol
nft {
name
symbol
address
}
name
symbol
cap
isDatatoken
holderCount
orderCount
orders(skip:0,first:1){
amount
serviceIndex
payer {
id
}
consumer{
id
}
estimatedUSDValue
lastPriceToken
lastPriceValue
}
}
}