mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
* GitBook: [#1] No subject * GitBook: [#2] No subject * GitBook: [#3] No subject * GitBook: [#4] No subject * GitBook: [#5] No subject * GitBook: [#6] Subgraph examples * GitBook: [#7] Subgraph examples * GitBook: [#8] Add hint for GraphQL interface
2.9 KiB
2.9 KiB
List all tokens
The result of following GraphQL query returns the information about datatokens.
{% hint style="info" %} Copy the query in the graphiQL interface to fetch the results from the mainnet. For other networks, change the domain name with appropriate subgraph domain as mentioned in this page. {% endhint %}
{
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
}
}
}
The python script below can be used to run the the query. If you wish to change the network, then replace the value of variable base_url
as needed.
{% tabs %} {% tab title="Python" %}
Create script
{% code title="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))
{% endcode %}
Execute script
python list_all_tokens.py
{% endtab %} {% endtabs %}
Sample Response
{
"data": {
"tokens": [
{
"cap": null,
"holderCount": "0",
"id": "0x0642026e7f0b6ccac5925b4e7fa61384250e1701",
"isDatatoken": false,
"name": "H2O",
"nft": null,
"orderCount": "0",
"orders": [],
"symbol": "H2O"
},
{
"cap": "115792089237316195423570985008687900000000000000000000000000",
"holderCount": "0",
"id": "0x122d10d543bc600967b4db0f45f80cb1ddee43eb",
"isDatatoken": true,
"name": "Brave Lobster Token",
"nft": {
"address": "0xea615374949a2405c3ee555053eca4d74ec4c2f0",
"name": "Ocean Data NFT",
"symbol": "OCEAN-NFT"
},
"orderCount": "0",
"orders": [],
"symbol": "BRALOB-11"
}
]
}
}