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, 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.
Deploying Graph-node using Docker Engine and Docker Compose
Prerequisites
A server for hosting Graph-node. See this guide for how to create a server;
Docker Compose and Docker Engine are installed and configured on the server. See this guide 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 for how to obtain the URL and the API key.
1. Create the /etc/docker/compose/graph-node/docker-compose.yml 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.
/etc/docker/compose/graph-node/docker-compose.yml (annotated - example for sepolia network)
Create the /etc/systemd/system/[email protected] file then copy and paste the following content to it. This example file could be customized if needed.
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
Environment="PROJECT=ocean"
WorkingDirectory=/etc/docker/compose/%i
ExecStartPre=/usr/bin/env docker-compose -p $PROJECT pull
ExecStart=/usr/bin/env docker-compose -p $PROJECT up -d
ExecStop=/usr/bin/env docker-compose -p $PROJECT stop
ExecStopPost=/usr/bin/env docker-compose -p $PROJECT down
[Install]
WantedBy=multi-user.target
3. Reload the systemd manager configuration
Run the following command to reload the systemd manager configuration
sudosystemctldaemon-reload
Optionally, you can enable the services to start at boot, using the following command:
To install Node.js locally, please refer to this link for instructions.
2. Download and extract Ocean-subgraph
Download and extract Ocean-subgraph (check here the available releases).
3. Install dependencies
From the directory where Ocean subgraph was extracted, run the following command:
npmi
4. Deploy Ocean Subgraph
In the following example, we are deploying on Ocean Subgraph on graph-node running for sepolia testnet.
Note: for ocean-subgraph deployment in the Kubernetes environment, both graph-node and ipfs services must be locally forwarded using kubectl port-forward command.
Run the following command:
$npmrunquickstart:sepolia>[email protected] quickstart:sepolia> node ./scripts/generatenetworkssubgraphs.js sepolia && npm run codegen && npm run create:local && npm run deploy:local
Creatingsubgraph.yamlforsepoliaAddingveOCEANSkippingpolygonSkippingbscSkippingenergywebSkippingmoonriverSkippingmainnetSkippingpolygonedgeSkippinggaiaxtestnetSkippingalfajoresSkippinggen-x-testnetSkippingfilecointestnet>[email protected] codegen> graph codegen --output-dir src/@typesSkipmigration:BumpmappingapiVersionfrom0.0.1to0.0.2Skipmigration:BumpmappingapiVersionfrom0.0.2to0.0.3Skipmigration:BumpmappingapiVersionfrom0.0.3to0.0.4Skipmigration:BumpmappingapiVersionfrom0.0.4to0.0.5Skipmigration:BumpmappingapiVersionfrom0.0.5to0.0.6Skipmigration:BumpmanifestspecVersionfrom0.0.1to0.0.2Applymigration:BumpmanifestspecVersionfrom0.0.2to0.0.4✔Applymigrations✔Loadsubgraphfromsubgraph.yamlLoadcontractABIfromnode_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.jsonLoadcontractABIfromabis/ERC20.json Load contract ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json
LoadcontractABIfromabis/ERC20.jsonLoadcontractABIfromnode_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.jsonLoadcontractABIfromnode_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.jsonLoadcontractABIfromnode_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
LoadcontractABIfromnode_modules/@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json✔LoadcontractABIs Generate types for contract ABI: ERC721Factory (node_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json)
Writetypestosrc/@types/ERC721Factory/ERC721Factory.tsGeneratetypesforcontractABI:ERC20 (abis/ERC20.json)Writetypestosrc/@types/ERC721Factory/ERC20.ts Generate types for contract ABI: FactoryRouter (node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json)
Writetypestosrc/@types/FactoryRouter/FactoryRouter.tsGeneratetypesforcontractABI:ERC20 (abis/ERC20.json)Writetypestosrc/@types/FactoryRouter/ERC20.ts Generate types for contract ABI: veAllocate (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json)
Writetypestosrc/@types/veAllocate/veAllocate.ts Generate types for contract ABI: veOCEAN (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json)
Writetypestosrc/@types/veOCEAN/veOCEAN.ts Generate types for contract ABI: veDelegation (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veDelegation.vy/veDelegation.json)
Writetypestosrc/@types/veDelegation/veDelegation.ts Generate types for contract ABI: veFeeDistributor (node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json)
Writetypestosrc/@types/veFeeDistributor/veFeeDistributor.ts Generate types for contract ABI: DFRewards (node_modules/@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json)
Writetypestosrc/@types/DFRewards/DFRewards.ts✔GeneratetypesforcontractABIsGeneratetypesfordatasourcetemplateERC20TemplateGeneratetypesfordatasourcetemplateERC721TemplateGeneratetypesfordatasourcetemplateDispenserGeneratetypesfordatasourcetemplateFixedRateExchangeWritetypesfortemplatestosrc/@types/templates.ts✔Generatetypesfordatasourcetemplates 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
LoaddatasourcetemplateABIfromabis/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
LoaddatasourcetemplateABIfromabis/ERC20.json Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json
LoaddatasourcetemplateABIfromabis/ERC20.json Load data source template ABI from node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json
LoaddatasourcetemplateABIfromabis/ERC20.json✔LoaddatasourcetemplateABIs Generate types for data source template ABI: ERC20Template > ERC20Template (node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json)
Writetypestosrc/@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)
Writetypestosrc/@types/templates/ERC20Template/ERC20TemplateEnterprise.tsGeneratetypesfordatasourcetemplateABI:ERC20Template>ERC20 (abis/ERC20.json)Writetypestosrc/@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)
Writetypestosrc/@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)
Writetypestosrc/@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)
Writetypestosrc/@types/templates/ERC721Template/ERC721RolesAddress.tsGeneratetypesfordatasourcetemplateABI:ERC721Template>ERC20 (abis/ERC20.json)Writetypestosrc/@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)
Writetypestosrc/@types/templates/Dispenser/Dispenser.tsGeneratetypesfordatasourcetemplateABI:Dispenser>ERC20 (abis/ERC20.json)Writetypestosrc/@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)
Writetypestosrc/@types/templates/FixedRateExchange/FixedRateExchange.tsGeneratetypesfordatasourcetemplateABI:FixedRateExchange>ERC20 (abis/ERC20.json)Writetypestosrc/@types/templates/FixedRateExchange/ERC20.ts✔GeneratetypesfordatasourcetemplateABIs✔LoadGraphQLschemafromschema.graphqlWritetypestosrc/@types/schema.ts✔GeneratetypesforGraphQLschemaTypesgeneratedsuccessfully>[email protected] create:local> graph create oceanprotocol/ocean-subgraph --node http://127.0.0.1:8020Createdsubgraph:oceanprotocol/ocean-subgraph>[email protected] deploy:local> graph deploy oceanprotocol/ocean-subgraph subgraph.yaml -l $npm_package_version --debug --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020
Skipmigration:BumpmappingapiVersionfrom0.0.1to0.0.2Skipmigration:BumpmappingapiVersionfrom0.0.2to0.0.3Skipmigration:BumpmappingapiVersionfrom0.0.3to0.0.4Skipmigration:BumpmappingapiVersionfrom0.0.4to0.0.5Skipmigration:BumpmappingapiVersionfrom0.0.5to0.0.6Skipmigration:BumpmanifestspecVersionfrom0.0.1to0.0.2Skipmigration:BumpmanifestspecVersionfrom0.0.2to0.0.4✔Applymigrations✔Loadsubgraphfromsubgraph.yamlCompiledatasource:ERC721Factory =>build/ERC721Factory/ERC721Factory.wasmCompiledatasource:FactoryRouter =>build/FactoryRouter/FactoryRouter.wasmCompiledatasource:veAllocate =>build/veAllocate/veAllocate.wasmCompiledatasource:veOCEAN =>build/veOCEAN/veOCEAN.wasmCompiledatasource:veDelegation =>build/veDelegation/veDelegation.wasmCompiledatasource:veFeeDistributor =>build/veFeeDistributor/veFeeDistributor.wasmCompiledatasource:DFRewards =>build/DFRewards/DFRewards.wasmCompiledatasourcetemplate:ERC20Template =>build/templates/ERC20Template/ERC20Template.wasmCompiledatasourcetemplate:ERC721Template =>build/templates/ERC721Template/ERC721Template.wasmCompiledatasourcetemplate:Dispenser =>build/templates/Dispenser/Dispenser.wasmCompiledatasourcetemplate:FixedRateExchange =>build/templates/FixedRateExchange/FixedRateExchange.wasm✔CompilesubgraphCopyschemafilebuild/schema.graphql Write subgraph file build/ERC721Factory/node_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json
Writesubgraphfilebuild/ERC721Factory/abis/ERC20.json Write subgraph file build/FactoryRouter/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json
Writesubgraphfilebuild/FactoryRouter/abis/ERC20.json Write subgraph file build/veAllocate/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json
Write subgraph file build/veOCEAN/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json
Write subgraph file build/veDelegation/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veDelegation.vy/veDelegation.json
Write subgraph file build/veFeeDistributor/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json
Write subgraph file build/DFRewards/node_modules/@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json
Write subgraph file build/ERC20Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json
Write subgraph file build/ERC20Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json
Writesubgraphfilebuild/ERC20Template/abis/ERC20.json Write subgraph file build/ERC20Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC20Roles.sol/ERC20Roles.json
Write subgraph file build/ERC721Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json
Write subgraph file build/ERC721Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC721RolesAddress.sol/ERC721RolesAddress.json
Writesubgraphfilebuild/ERC721Template/abis/ERC20.json Write subgraph file build/Dispenser/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json
Writesubgraphfilebuild/Dispenser/abis/ERC20.json Write subgraph file build/FixedRateExchange/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json
Writesubgraphfilebuild/FixedRateExchange/abis/ERC20.jsonWritesubgraphmanifestbuild/subgraph.yaml✔Writecompiledsubgraphtobuild/AddfiletoIPFSbuild/schema.graphql..QmQa3a9ypCLC84prHGQdhbcGG4DHJceqADGxmZMmAAXuTz Add file to IPFS build/ERC721Factory/node_modules/@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json
..QmSoG3r5vyWXqjEfKAQYjwtQcQkZCsZEcJXVFWVq1tT1dDAddfiletoIPFSbuild/ERC721Factory/abis/ERC20.json..QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2 Add file to IPFS build/FactoryRouter/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json
..QmcBVA1R3yi2167UZMvV4LvG4cMHjL8ZZXmPMriCjn8DEeAddfiletoIPFSbuild/FactoryRouter/abis/ERC20.json..QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2 (already uploaded) Add file to IPFS build/veAllocate/node_modules/@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json
..Qmc3iwQkQAhqe1PjzTt6KZLh9rsWQvyxkFt7doj2iXv8C3AddfiletoIPFSbuild/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
..QmcckRMahzpL7foEFGpWfkDBsyoWbNRfLC32uFq8ceUV3aAddfiletoIPFSbuild/ERC721Factory/ERC721Factory.wasm..QmVfDAgZdKWxMuNfT7kso1LbFre2xhYbEeHBGm3gH3R9oEAddfiletoIPFSbuild/FactoryRouter/FactoryRouter.wasm..QmYCC9AcaYw3nGSqNXNFHVsuB67FQEyZ8twRjRXrprcgypAddfiletoIPFSbuild/veAllocate/veAllocate.wasm..QmUFaYDxChi5nKEJLvHQZP1cRoqqP5k3fYSwk2JjuSceiJAddfiletoIPFSbuild/veOCEAN/veOCEAN.wasm..QmRYCyYKwHdSeM55vuvL1mdCooDkFQm6d2TQ7iK2N1qgurAddfiletoIPFSbuild/veDelegation/veDelegation.wasm..QmaTjRLirzfidtQTYgzxqVVD9AX9e69TN1Y8fEsNQ9AEZqAddfiletoIPFSbuild/veFeeDistributor/veFeeDistributor.wasm..QmZCEp4yxiDyuksEjSaceogJwLMto2UGfV1KxVuJTJLTqgAddfiletoIPFSbuild/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
..QmZnogwnfr4TeBPykvmCL2oaX63AKQP1F1uBAbbfnyPAzBAddfiletoIPFSbuild/ERC20Template/abis/ERC20.json..QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2 (already uploaded) Add file to IPFS build/ERC20Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC20Roles.sol/ERC20Roles.json
..QmTWTzg4jTx4GxGApVyxirNRTxB7QovS4bHGuWnnW8Ciz2AddfiletoIPFSbuild/templates/ERC20Template/ERC20Template.wasm..QmUcxes5La7n9481Vf9AoQ2Mjt1CrbS7T6tDhpnfF77Uh5 Add file to IPFS build/ERC721Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json
..QmPE82CiACicgu1WxEjeFrLmskiJADroQRnxH7owpK6jaP Add file to IPFS build/ERC721Template/node_modules/@oceanprotocol/contracts/artifacts/contracts/utils/ERC721RolesAddress.sol/ERC721RolesAddress.json
..Qmdhi7UK6Ww8vXH9YC3JxVUEFjTyx3XycF53rRZapVK5c3AddfiletoIPFSbuild/ERC721Template/abis/ERC20.json..QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2 (already uploaded)AddfiletoIPFSbuild/templates/ERC721Template/ERC721Template.wasm..QmNhLws24szwpz8LM2sL6HHKc6KK4vtJwzfeZWkghuqn7Q Add file to IPFS build/Dispenser/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json
..QmdiN7Fhw9sjoVVJgHtTtzxv5fwtFMHLNH1x1yqbswsThWAddfiletoIPFSbuild/Dispenser/abis/ERC20.json..QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2 (already uploaded)AddfiletoIPFSbuild/templates/Dispenser/Dispenser.wasm..QmTpn9wagpmH6byjjdCBZdgypFgcw2mva3bC52nC4z3eLW Add file to IPFS build/FixedRateExchange/node_modules/@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json
..Qmd2ToAptK74j8pGxe8mZXfAvY3AxstgmYH8JDMAfLtAGdAddfiletoIPFSbuild/FixedRateExchange/abis/ERC20.json..QmXuTbDkNrN27VydxbS2huvKRk62PMgUTdPDWkxcr2w7j2 (already uploaded)AddfiletoIPFSbuild/templates/FixedRateExchange/FixedRateExchange.wasm..QmRrwwoFF33LvPhnGCGgLBLyuLizrFgD44kW9io81tPZzX✔UploadsubgraphtoIPFSBuildcompleted:QmVUKpgwuyDh9KgUxTzZvVNFJbdevc56YrZpZjQvu8Yp7qDeployedtohttp://127.0.0.1:8000/subgraphs/name/oceanprotocol/ocean-subgraph/graphqlSubgraphendpoints:Queries (HTTP): http://127.0.0.1:8000/subgraphs/name/oceanprotocol/ocean-subgraph