How to deploy Subgraphs on Zeeve? Step-by-Step Guide
Tags: subgraphs, zeeve
Published: 2024-02-14 09:27:45

<p>Subgraph from The Graph Network tackles all the challenges of a traditional API-based data query method. Problems are mainly slow response, limited query, and complexity of managing multiple APIs.&nbsp;</p>
<p>Now with <a href="https://www.zeeve.io/subgraphs/">Hosted Subgraph</a>, projects can easily set up their own <a href="https://www.zeeve.io/subgraphs/">blockchain data indexing solution</a> and query data endlessly. Again, you may come across challenges while launching and managing your Subgraphs, such as downtime, slow indexing, less control over Subgraph infrastructure, and no direct support. To provide a solution, <a href="https://www.zeeve.io/">Zeeve</a> is offering a reliable, enterprise-grade Subgraph-managed infrastructure that allows all kinds of web3 applications and networks to easily <a href="https://www.zeeve.io/subgraphs/">deploy their Subgraph</a> and query data.&nbsp;</p>
<p>This article explains the step-by-step process of how you can <a href="https://www.zeeve.io/subgraphs/">deploy Subgraphs</a> on Zeeve. Also, we will be briefing the Subgraph creation process and additional features supported on <a href="https://www.zeeve.io/">Zeeve</a>, which are effortless Subgraph migration and Webhooks integration. Before that, let’s quickly understand why Zeeve-managed Subgraphs can be a viable solution for data consumers.</p>
<figure class="wp-block-image aligncenter size-large"><a href="https://www.zeeve.io/subgraphs/"><img src="https://www.zeeve.io/wp-content/uploads/2024/02/Index-blockchain-data-4-5x-faster-for-all-your-applications-1024x130.jpg" alt="How to deploy Subgraphs on Zeeve" class="wp-image-58817"/></a></figure>
<h2>What makes Zeeve-managed Subgraph an ideal choice for dApps?</h2>
<ul><!-- wp:list-item -->
<li><strong>Webhooks for real-time data indexing: </strong>Enable Webhooks in your <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> to keep a track of real-time data changes into all the entities you specify. Webhooks works with Subgraphs simultaneously, allowing you to fetch both real-time and indexed data with ease.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Ultrafast data indexing with zero downtime: </strong><a href="https://www.zeeve.io/subgraphs/">Zeeve’s Subgraph infrastructure</a> is optimized to serve upto 4-5x faster data indexing with minimal data lag.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Support for diverse blockchains:</strong> Zeeve supports <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> creation for a range of blockchains, even the ones which are not supported for The Graph decentralized and hosted service.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Hassle-free, low-cost infrastructure maintenance: </strong>With <a href="https://www.zeeve.io/">Zeeve</a>, you get a highly-optimized and production-ready infrastructure to <a href="https://www.zeeve.io/subgraphs/">deploy your Subgraphs</a> at significantly lower cost, and in a hassle-free way.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Guaranteed reliability:</strong> Zeeve guaranteed reliability for Subgraph service with 99.9% API SLA uptime.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>Effortless Subgraph migration: </strong>Migrate your existing Subgraphs in one-click on Zeeve-managed infrastructure.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><strong>24/7 monitoring and logs: </strong>All your Subgraphs deployed on Zeeve will be monitored 24/7 and logs will be presented on the dashboard itself, ensuring performance and uptime.</li>
<!-- /wp:list-item --></ul>
<h2>Build and deploy your Subgraph with Zeeve: The hassle-free, Low-code way</h2>
<p>As you might already know, there are multiple ways to build and <a href="https://www.zeeve.io/subgraphs/">deploy Subgraphs</a>. For example,&nbsp;</p>
<ul><!-- wp:list-item -->
<li>You can build a Subgraph from source code,&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Deploy Subgraph to The Graph’s hosted service, or&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Choose the low-code option available with <a href="https://www.zeeve.io/">Zeeve</a>.&nbsp;</li>
<!-- /wp:list-item --></ul>
<p>For this article, we will discuss the most relevant way– the low-code option, now available on Zeeve. Also, note that the hosted service at The Graph Network is in the process of sunsetting and it will be unavailable soon except for the networks that are not yet supported on Graph’s decentralized network. Note that there can be two main instances to <a href="https://www.zeeve.io/subgraphs/">deploy a Subgraph</a>.</p>
<p>Here, there can be two scenarios– either you need to deploy a Subgraph from scratch or migrate from Graph Hosted service to managed services provider like Zeeve. We will discuss both the requirements in this article:</p>
<ol><!-- wp:list-item -->
<li><strong>Building and deploying a Subgraph from Scratch:</strong></li>
<!-- /wp:list-item --></ol>
<p>To <a href="https://www.zeeve.io/subgraphs/">deploy your Subgraph</a> on Zeeve, you first need to create your Subgraph through the step-by-step mentioned below. However, if you want, Zeeve will build a custom-fitted Subgraph for your dApps or any web3 project.&nbsp;</p>
<p><strong>What you’ll need:</strong></p>
<p>&gt;Access to <a href="https://www.zeeve.io/">Zeeve</a>. (sign up and create your account)</p>
<p>&gt;Graph CLI Installed.</p>
<p>&gt;A properly compiled:</p>
<li>Subgraph Manifest</li>
<li>GraphQL Schema</li>
<li>Assembly Script Mappings.</li>
<p>&gt;The contract address for which indexing.</p>
<p>&gt;ABI&nbsp; (Application Binary Interface) files for the contract.</p>
<h2>A video walkthrough:</h2>
<iframe width="620" height="530" src="https://www.youtube.com/embed/i3dV4qsK5nc?si=O8blvd0geVFqsKIu" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
<p>With all the prerequisites, let’s start the Subgraph creation:</p>
<li><strong>Install Graph CLI:&nbsp;</strong></li>
<p>With yarn:</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>yarn global add @graphprotocol/graph-cli</code></pre>
<p>With npm:</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>npm install -g @graphprotocol/graph-cli</code></pre>
<li><strong>Create your Subgraph:</strong></li>
<p>Initiate a new Subgraph using the below command, plus adding a relevant Subgraph slug. For example, we are adding– “my-new-subgraph”</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>graph init --studio my-new-subgraph</code></pre>
<p>Or, you can create a Subgraph that will index data from an existing contract. Use the below command with your own Subgraph-specific details.&nbsp;</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>graph init \
&nbsp; --product subgraph-studio \
&nbsp; --from-contract 0x123abc456def789ghi \
&nbsp; --network ethereum\
&nbsp; --abi my-contract.abi \
&nbsp; my-new-subgraph</code></pre>
<p>The &lt;SUBGRAPH_SLUG&gt; (&nbsp; my-new-subgraph in this case)is the ID of your subgraph in Subgraph Studio, it can be found on your subgraph details page.</p>
<li><strong>Modify your existing Subgraph to add new data sources</strong></li>
<p>Since v0.31.0 the graph-cli supports adding new dataSources to an existing <a href="https://www.zeeve.io/subgraphs/">subgraph</a> through the graph add command.</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>graph add &lt;address&gt; &#91;&lt;subgraph-manifest <strong>default</strong>: "./subgraph.yaml"&gt;]

<strong>Options</strong>:

&nbsp; &nbsp; &nbsp; --abi &lt;path&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Path to the contract ABI (default: download from Etherscan)
&nbsp; &nbsp; &nbsp; --contract-name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name of the contract (default: Contract)
&nbsp; &nbsp; &nbsp; --merge-entities&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Whether to merge entities with the same name (default: false)
&nbsp; &nbsp; &nbsp; --network-file &lt;path&gt; &nbsp; &nbsp; Networks config file path (default: "./networks.json")</code></pre>
<p>The add command will fetch ABI from Etherscan (unless you specify the --abi file. Plus, it will create a new dataSource for your Subgraph similar to how the graph init command creates dataSource --from-contract.&nbsp;</p>
<li><strong>Write your Subgraph manifest.</strong></li>
<p>The subgraph manifest– subgraph.yaml file will define which smart contract your Subgraph will index, the events, and the way of mapping event data to the entities.&nbsp; Below is an example manifest, you can add specifications based on your Subgraph.</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>specVersion: 0.0.4
description: Swap Data for Ethereum Subgraph
repository: https://github.com/your-username/swap-data-ethereum
schema:
  file: ./schema.graphql
indexerHints:
  prune: auto
dataSources:
  - kind: ethereum/contract
    name: SwapContract
    network: mainnet
    source:
      address: '0x12aBc34De56Ef78GhI90jKlMnOpQrStUvWxYz'
      abi: SwapContract
      startBlock: 5000000
      endBlock: 6000000
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.6
      language: wasm/assemblyscript
      entities:
        - Swap
      abis:
        - name: SwapContract
          file: ./abis/SwapContract.json
      eventHandlers:
        - event: SwapExecuted(uint256,address,address,uint256,uint256)
          handler: handleSwapExecuted
      file: ./src/mapping.ts</code></pre>
<li><strong>Get the ABI Files</strong></li>
<p>Following are the main ways to obtain ABI files. Ensure that your ABI file(s) must match the contract(s).</p>
<ul><!-- wp:list-item -->
<li>If you are creating a new project, you can access the contract address and ABI right away.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>For public Subgraph projects, you can get ABI though truffle compile or solc compile.&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Additionally, you can use Etherscan or similar explorer to get the ABIs.</li>
<!-- /wp:list-item --></ul>
<li><strong>Compile GraphQL Schema</strong></li>
<p>GraphQL schema decides what data your Subgraph will store and how it will query data via GraphQL. Following is the schema for a single token entity. You can customize the schema as needed.</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>{
&nbsp; token(<strong>id</strong>: "1") {
&nbsp; &nbsp; id
&nbsp; &nbsp; owner
&nbsp; }
}</code></pre>
<li><strong>Define the Entities</strong></li>
<p>Specify entity types in your&nbsp; schema.graphql, and your Subgraph will produce all the top level&nbsp; fields that query single instances and collections related to that entity type.&nbsp; The Swaps entity below is structured around a Swaps object and is a good example of how an entity should be defined.</p>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>type SwapsForEthereum @entity(binance: true) {
  id: Bytes!
  owner: Bytes
  displayName: String
  imageUrl: String
  accepted: Boolean
}
}</code></pre>
<p>Now that your <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> is created, head to deployment on the Zeeve-managed Hosting Subgraph infrastructure. Following the step-by-step instructions:</p>
<p><strong>Step:1</strong> Login or create an account on <a href="https://www.zeeve.io/">Zeeve</a>. Navigate to the ‘Hosted Subgraphs’ located at the left-side panel of the dashboard. Buy a subscription for Subgraps(s)based on your project requirement. Also, you can go for services add-ons (that we will discuss later) and additional queries. Immediately after the payment is done, your subscription for Subgraph will be active. You can now proceed to deployment, hence.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xgab5lh75pina3nkqzor.png)
<p><strong>Step:2</strong> Again, navigate to Hosted Service, click ‘Add Subgraph,’ and continue with Create New. Steps for importing your existing Subgraph will be discussed in a separate section in a while. Tapping on the Create New option, a new page will appear asking for basic details such as the name of your Subgraph, workspace, and the blockchain network from which you will fetch data through your <a href="https://www.zeeve.io/subgraphs/">Subgraph</a>. Choose any network from the drop-down list or add your custom network by providing the respective RPC Endpoint. </p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ld45vbp2l53s3lhv3bqj.png)
<p><strong>Step3:</strong>&nbsp; Click on ‘Add Subgraph’, and a quick authentication will take you to the Subgraph details page. Information on this details page includes details such as Subgraph status– deployed or in progress, sync status with current and latest block, total requests, API units consumed to date, successful requests, and invalid requests. Details specific to your Subgraph will be the creation date, selected <a href="https://zeeve.io/blockchain-protocols/">blockchain network</a>, and workspace type.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8af4k4o6cx335x8zdvuw.png)
<p>&nbsp;Also, you will get ‘Deployment Command’ and ‘Query URL’ on this same page. With this Deployment command, go to the CLI terminal and complete your Subgraph’s deployment.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0ukuqq9a8itg1vy8htw.png)
<p>Click on the Query URL to track all the successful requests on your Subgraph. These results are stored in a PostgreSQL database.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdjpolj7ov30zfkmpa6x.png)
<p><strong>Step:4</strong> Click on the Log button of any deployed subgraph to get real-time status information about the sync's progress.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cz1z2fzyo2e4xnvto8a.png)
<li><strong>Migrating from The Graph’s Hosted Service Subgraph to Zeeve Subgraph Infrastructure:</strong></li>
<p><a href="https://www.zeeve.io/">Zeeve</a> allows you to import your existing Subgraphs to the Zeeve-managed infrastructure, be it from The Graph’s decentralized network or on the Graph’s hosted service. For that, you simply need to log in to Zeeve→navigate to Hosted Subgraphs—&gt;click on ‘Import Existing.’ You will see a details page similar to the one below, asking for details such as Subgraph URL, Workspace, and Network.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnulcu4mrmutcn4mddld.png)
<p>Once you provide all the details, click on next to verify your Subgraph-related details. Enter Submit and your Subgraph will successfully migrate to Zeeve infrastructure.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/icsyhq3gbz8zysrx97sz.png)
<p>Similar to how Zeeve monitors your newly created Subgraphs, it will also check logs of your imported Subgraph. Go to the <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> details screen and check logs from there. Here’s an example:</p>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnbp9uddblajskh3jdpk.png)
<p><strong>Enable Webhook for your Subgraphs&nbsp;</strong></p>
<p>To enable Webhooks in your Subgraph, navigate to your Subgraph (deployed or under deployment), click on Webhooks, and then enable webhook.&nbsp;</p>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jngp893x5w0sha2txqxz.png)
<p>Note: You first need to purchase Webhooks to be able to enable them into your Subgraphs.</p>

<p>Provide details for the Webhook— entities and URL. Click on Continue to enable Webhook.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/buf23gaz6bjg637hxh1g.png)


<p>Now, you can track real-time data changes across all your specified entities in tabular form, shown in the below image:</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a50wr231ba6uaaf0yzqk.png)

<p>Note: You first need to purchase Webhooks to be able to enable them into your Subgraphs.</p>
<h2 id="h-let-s-wrap">Let’s Wrap!</h2>
<p>That’s it! Our discussion around <a href="https://www.zeeve.io/subgraphs/">Subgraph deployment</a> on <a href="https://www.zeeve.io/">Zeeve</a> from scratch and migration of existing Subgraph, is done. Now that you know how to deploy Subgraphs on Zeeve, you can easily sign up and initiate your Subgraph creation. Additionally, Zeeve offers support of highly experienced web3 developers who will build your <a href="https://www.zeeve.io/subgraphs/">custom Subgraph</a> at lower cost and in less time for faster time-to-market. For more information <a href="https://www.zeeve.io/subgraphs/">Zeeve-managed Subgraphs</a> or to understand other rest of the blockchain services, feel free to connect with us. You can mail us your queries or <a href="https://www.zeeve.io/talk-to-an-expert/">schedule a one-on-one call</a> for a dedicated discussion.</p>