Ocean subgraph allows querying the datatoken, data NFT, and all event information using GraphQL. Hosting the Ocean subgraph saves the cost and time required in querying the data directly from the blockchain. The steps in this tutorial will explain how to host Ocean subgraph for the EVM-compatible chains supported by Ocean Protocol.
Ocean Subgraph is deployed on top of [graph-node](https://github.com/graphprotocol/graph-node), therefore, in this document, we will show first how to deploy graph-node - either using Docker Engine or Kubernetes - and then how to install Ocean Subgraph on the graph-node system.
* A server for hosting Graph-node. See [this guide](setup-server.md) for how to create a server;
* Docker Compose and Docker Engine are installed and configured on the server. See [this guide](setup-server.md#install-docker-engine-and-docker-compose) for how to install these products.
* The RPC URLs and API keys for each of the networks to which Ocean Subgraph will be connected. See [this guide](https://github.com/oceanprotocol/docs/blob/main/developers/obtaining-api-keys-for-blockchain-access.md) for how to obtain the URL and the API key.
1. [Create the /etc/docker/compose/graph-node/docker-compose.yml file](deploying-ocean-subgraph.md#1-create-the-etcdockercomposegraph-nodedocker-composeyml-file)
2. [Create the /etc/systemd/system/docker-compose@graph-node.service file](deploying-ocean-subgraph.md#2-create-the-etcsystemdsystemdocker-composegraph-nodeservice-file)
From a terminal console, create the _/etc/docker/compose/graph-node/docker-compose.yml_ file, then copy and paste the following content to it (. Check the comments in the file and replace the fields with the specific values of your implementation.
#### 2. Create the /etc/systemd/system/docker-compose@graph-node.service file
Create the _/etc/systemd/system/docker-compose@graph-node.service_ file then copy and paste the following content to it. This example file could be customized if needed.
In this example, we will deploy graph-node as a Kubernetes deployment service. [graph-node](https://github.com/graphprotocol/graph-node) has the following dependencies: PostgreSQL and IPFS.
### Prerequisites:
* A server for hosting graph-node. See [this guide](setup-server.md) for how to create a server;
* Kubernetes with Docker Engine is installed and configured on the server. See [this chapter](setup-server.md#install-kubernetes-with-docker-engine) for information on installing Kubernetes.
* The RPC URLs and API keys for each of the networks to which the Provider will be connected. See [this guide](https://github.com/oceanprotocol/docs/blob/main/developers/obtaining-api-keys-for-blockchain-access.md) for how to obtain the URL and the API key.
To install Node.js locally, please refer to this [link ](https://nodejs.org/en/download)for instructions.
#### 2. Download and extract Ocean-subgraph
Download and extract [Ocean-subgraph](https://github.com/oceanprotocol/ocean-subgraph) (check [here](https://github.com/oceanprotocol/ocean-subgraph/releases) the available releases).
#### 3. Install dependencies
From the directory where Ocean subgraph was extracted, run the following command:
Note: for `ocean-subgraph` deployment in the Kubernetes environment, both `graph-node` and `ipfs` services must be locally forwarded using `kubectl port-forward` command.
Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
Apply migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json
Load contract ABI from abis/ERC20.json
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json
Load contract ABI from abis/ERC20.json
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veDelegation.vy/veDelegation.json
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json
Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json
✔ Load contract ABIs
Generate types for contract ABI: ERC721Factory (node_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json)
Write types to src/@types/ERC721Factory/ERC721Factory.ts
Generate types for contract ABI: ERC20 (abis/ERC20.json)
Write types to src/@types/ERC721Factory/ERC20.ts
Generate types for contract ABI: FactoryRouter (node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json)
Write types to src/@types/FactoryRouter/FactoryRouter.ts
Generate types for contract ABI: ERC20 (abis/ERC20.json)
Write types to src/@types/FactoryRouter/ERC20.ts
Generate types for contract ABI: veAllocate (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json)
Write types to src/@types/veAllocate/veAllocate.ts
Generate types for contract ABI: veOCEAN (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json)
Write types to src/@types/veOCEAN/veOCEAN.ts
Generate types for contract ABI: veDelegation (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veDelegation.vy/veDelegation.json)
Write types to src/@types/veDelegation/veDelegation.ts
Generate types for contract ABI: veFeeDistributor (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json)
Write types to src/@types/veFeeDistributor/veFeeDistributor.ts
Generate types for contract ABI: DFRewards (node_modules/@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json)
Write types to src/@types/DFRewards/DFRewards.ts
✔ Generate types for contract ABIs
Generate types for data source template ERC20Template
Generate types for data source template ERC721Template
Generate types for data source template Dispenser
Generate types for data source template FixedRateExchange
Write types for templates to src/@types/templates.ts
✔ Generate types for data source templates
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json
Load data source template ABI from abis/ERC20.json
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC20Roles.sol/ERC20Roles.json
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC721RolesAddress.sol/ERC721RolesAddress.json
Load data source template ABI from abis/ERC20.json
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json
Load data source template ABI from abis/ERC20.json
Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json
Load data source template ABI from abis/ERC20.json
✔ Load data source template ABIs
Generate types for data source template ABI: ERC20Template > ERC20Template (node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json)
Write types to src/@types/templates/ERC20Template/ERC20Template.ts
Generate types for data source template ABI: ERC20Template > ERC20TemplateEnterprise (node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json)
Write types to src/@types/templates/ERC20Template/ERC20TemplateEnterprise.ts
Generate types for data source template ABI: ERC20Template > ERC20 (abis/ERC20.json)
Write types to src/@types/templates/ERC20Template/ERC20.ts
Generate types for data source template ABI: ERC20Template > ERC20Roles (node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC20Roles.sol/ERC20Roles.json)
Write types to src/@types/templates/ERC20Template/ERC20Roles.ts
Generate types for data source template ABI: ERC721Template > ERC721Template (node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json)
Write types to src/@types/templates/ERC721Template/ERC721Template.ts
Generate types for data source template ABI: ERC721Template > ERC721RolesAddress (node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC721RolesAddress.sol/ERC721RolesAddress.json)
Write types to src/@types/templates/ERC721Template/ERC721RolesAddress.ts
Generate types for data source template ABI: ERC721Template > ERC20 (abis/ERC20.json)
Write types to src/@types/templates/ERC721Template/ERC20.ts
Generate types for data source template ABI: Dispenser > Dispenser (node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json)
Write types to src/@types/templates/Dispenser/Dispenser.ts
Generate types for data source template ABI: Dispenser > ERC20 (abis/ERC20.json)
Write types to src/@types/templates/Dispenser/ERC20.ts
Generate types for data source template ABI: FixedRateExchange > FixedRateExchange (node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json)
Write types to src/@types/templates/FixedRateExchange/FixedRateExchange.ts
Generate types for data source template ABI: FixedRateExchange > ERC20 (abis/ERC20.json)
Write types to src/@types/templates/FixedRateExchange/ERC20.ts
Add file to IPFS build/veAllocate/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json
.. Qmc3iwQkQAhqe1PjzTt6KZLh9rsWQvyxkFt7doj2iXv8C3
Add file to IPFS build/veOCEAN/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json
.. QmahFjirJqiwKpytFZ9CdE92LdPGBUDZs6AWpsrH2wn1VP
Add file to IPFS build/veDelegation/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veDelegation.vy/veDelegation.json
.. QmfU6kZ5sksLdj3q88n7SUP63C1cnhQjU8vuMmRYwf2v5r
Add file to IPFS build/veFeeDistributor/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json
.. QmVU51oBr62D4UFXTwnMcbzuBBAAeQssqmqM9jic7A6L3v
Add file to IPFS build/DFRewards/node_modules/@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json
.. QmcckRMahzpL7foEFGpWfkDBsyoWbNRfLC32uFq8ceUV3a
Add file to IPFS build/ERC721Factory/ERC721Factory.wasm
.. QmVfDAgZdKWxMuNfT7kso1LbFre2xhYbEeHBGm3gH3R9oE
Add file to IPFS build/FactoryRouter/FactoryRouter.wasm
.. QmYCC9AcaYw3nGSqNXNFHVsuB67FQEyZ8twRjRXrprcgyp
Add file to IPFS build/veAllocate/veAllocate.wasm
.. QmUFaYDxChi5nKEJLvHQZP1cRoqqP5k3fYSwk2JjuSceiJ
Add file to IPFS build/veOCEAN/veOCEAN.wasm
.. QmRYCyYKwHdSeM55vuvL1mdCooDkFQm6d2TQ7iK2N1qgur
Add file to IPFS build/veDelegation/veDelegation.wasm
.. QmaTjRLirzfidtQTYgzxqVVD9AX9e69TN1Y8fEsNQ9AEZq
Add file to IPFS build/veFeeDistributor/veFeeDistributor.wasm
.. QmZCEp4yxiDyuksEjSaceogJwLMto2UGfV1KxVuJTJLTqg
Add file to IPFS build/DFRewards/DFRewards.wasm
.. QmRSxe52B836bdfoJbuDY4tUCawzqgkHRNxe9ucU1JdYm5
Add file to IPFS build/ERC20Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json
.. QmPkhFvnBbqA3You7NsK5Zsyh8kkizXUHF9pcC5V6qDJQu
Add file to IPFS build/ERC20Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json
.. QmZnogwnfr4TeBPykvmCL2oaX63AKQP1F1uBAbbfnyPAzB
Add file to IPFS build/ERC20Template/abis/ERC20.json
Add file to IPFS build/templates/Dispenser/Dispenser.wasm
.. QmTpn9wagpmH6byjjdCBZdgypFgcw2mva3bC52nC4z3eLW
Add file to IPFS build/FixedRateExchange/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json
.. Qmd2ToAptK74j8pGxe8mZXfAvY3AxstgmYH8JDMAfLtAGd
Add file to IPFS build/FixedRateExchange/abis/ERC20.json
Ocean Subgraph is deployed under /subgraphs/name/oceanprotocol/ocean-subgraph/. To access it from the server on which it was deployed, open a browser and go to [http://127.0.0.1:8000/subgraphs/name/oceanprotocol/ocean-subgraph/graphql](http://127.0.0.1:8000/subgraphs/name/oceanprotocol/ocean-subgraph/graphql).