Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
* [Deploying Aquarius](building-with-ocean/deploying-components/deploying-aquarius.md)
* [Deploying Provider](building-with-ocean/deploying-components/deploying-provider.md)
* [Deploying Ocean subgraph](building-with-ocean/deploying-components/deploying-ocean-subgraph.md)
* [Using Ocean Subgraph](building-with-ocean/using-ocean-subgraph/README.md)
* [List data NFTs](building-with-ocean/using-ocean-subgraph/list-data-nfts.md)
* [List all tokens](building-with-ocean/using-ocean-subgraph/list-datatokens.md)
* [Get data NFT information](building-with-ocean/using-ocean-subgraph/get-data-nft-information.md)
* [Get datatoken information](building-with-ocean/using-ocean-subgraph/get-datatoken-information.md)
* [List Fixed Rate Exchanges](building-with-ocean/using-ocean-subgraph/list-fixed-rate-exchanges.md)
* [Contributing](core-concepts/contributing.md)
* [Contributor Code of Conduct](core-concepts/code-of-conduct.md)
* [Legal Requirements](core-concepts/legal-reqs.md)
Expand Down
10 changes: 10 additions & 0 deletions building-with-ocean/using-ocean-subgraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
description: >-
Ocean subgraph is an off-chain service which provides information about
datatokens, users, balances using the GraphQL. Ocean subgraph provides a
faster way to fetch data rather than on-chain query.
---

# Using Ocean Subgraph

For each supported network, an individual Ocean subgraph is deployed. The information about supported networks and the subgraph URL is available on [this page](../../core-concepts/networks.md).
130 changes: 130 additions & 0 deletions building-with-ocean/using-ocean-subgraph/get-data-nft-information.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Get data NFT information

The result of following GraphQL query returns the information about a particular datatoken. Here, `0x1c161d721e6d99f58d47f709cdc77025056c544c` is the address of the dataNFT.  

{% hint style="info" %}
Copy the query in the [graphiQL interface](https://v4.subgraph.mainnet.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql) to fetch the results from the mainnet. For other networks, change the domain name with appropriate subgraph domain as mentioned in [this page](../../core-concepts/networks.md).
{% endhint %}

```graphql
{
nft (id:"0x1c161d721e6d99f58d47f709cdc77025056c544c", subgraphError:deny){
id
name
symbol
owner
address
assetState
tx
block
transferable
creator
createdTimestamp
providerUrl
managerRole
erc20DeployerRole
storeUpdateRole
metadataRole
tokenUri
template
orderCount
}
}b
```

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. Change the value of the variable dataNFT\_address with the address of the datatoken of your choice.

{% tabs %}
{% tab title="Python" %}
{% code title="dataNFT_information.py" %}
```python
import requests
import json

dataNFT_address = "0x1c161d721e6d99f58d47f709cdc77025056c544c"
query = """
{{
nft (id:"{0}", subgraphError:deny){{
id
name
symbol
owner
address
assetState
tx
block
transferable
creator
createdTimestamp
providerUrl
managerRole
erc20DeployerRole
storeUpdateRole
metadataRole
tokenUri
template
orderCount
}}
}}""".format(
dataNFT_address
)

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 dataNFT_information.py
```
{% endtab %}
{% endtabs %}

<details>

<summary>Sample response</summary>

```json
{
"data": {
"nft": {
"address": "0x1c161d721e6d99f58d47f709cdc77025056c544c",
"assetState": 0,
"block": 15185270,
"createdTimestamp": 1658397870,
"creator": "0xd30dd83132f2227f114db8b90f565bca2832afbd",
"erc20DeployerRole": [
"0x1706df1f2d93558d1d77bed49ccdb8b88fafc306"
],
"id": "0x1c161d721e6d99f58d47f709cdc77025056c544c",
"managerRole": [
"0xd30dd83132f2227f114db8b90f565bca2832afbd"
],
"metadataRole": null,
"name": "Ocean Data NFT",
"orderCount": "1",
"owner": "0xd30dd83132f2227f114db8b90f565bca2832afbd",
"providerUrl": "https://v4.provider.mainnet.oceanprotocol.com",
"storeUpdateRole": null,
"symbol": "OCEAN-NFT",
"template": "",
"tokenUri": "<removed>",
"transferable": true,
"tx": "0x327a9da0d2e9df945fd2f8e10b1caa77acf98e803c5a2f588597172a0bcbb93a"
}
}
}
```

</details>
166 changes: 166 additions & 0 deletions building-with-ocean/using-ocean-subgraph/get-datatoken-information.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Get datatoken information



The result of following GraphQL query returns the information about a particular datatoken. Here, `0x122d10d543bc600967b4db0f45f80cb1ddee43eb` is the address of the datatoken. &#x20;

{% hint style="info" %}
Copy the query in the [graphiQL interface](https://v4.subgraph.mainnet.oceanprotocol.com/subgraphs/name/oceanprotocol/ocean-subgraph/graphql) to fetch the results from the mainnet. For other networks, change the domain name with appropriate subgraph domain as mentioned in [this page](../../core-concepts/networks.md).
{% endhint %}

```graphql
{
token(id:"0x122d10d543bc600967b4db0f45f80cb1ddee43eb", 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
}
}
fixedRateExchanges(subgraphError:deny){
id
price
active
}
}
```

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. Change the value of the variable `datatoken_address` with the address of the datatoken of your choice.

{% tabs %}
{% tab title="Python" %}
#### Create script

{% code title="datatoken_information.py" %}
```python
import requests
import json

datatoken_address = "0x122d10d543bc600967b4db0f45f80cb1ddee43eb"
query = """
{{
token(id:"{0}", 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
}}
}}
fixedRateExchanges(subgraphError:deny){{
id
price
active
}}
}}""".format(
datatoken_address
)

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 datatoken_information.py
```
{% endtab %}
{% endtabs %}

<details>

<summary>Sample response</summary>

```json
{
"data": {
"fixedRateExchanges": [
{
"active": true,
"id": "0xfa48673a7c36a2a768f89ac1ee8c355d5c367b02-0x06284c39b48afe5f01a04d56f1aae45dbb29793b190ee11e93a4a77215383d44",
"price": "33"
},
{
"active": true,
"id": "0xfa48673a7c36a2a768f89ac1ee8c355d5c367b02-0x2719862ebc4ed253f09088c878e00ef8ee2a792e1c5c765fac35dc18d7ef4deb",
"price": "35"
},
{
"active": true,
"id": "0xfa48673a7c36a2a768f89ac1ee8c355d5c367b02-0x2dccaa373e4b65d5ec153c150270e989d1bda1efd3794c851e45314c40809f9c",
"price": "33"
}
],
"token": {
"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"
}
}
}
```

</details>
Loading