Mastering Real-time Data Streaming Game with Webhooks in Zeeve Subgraph
Tags: subgraphs, zeeve
Published: 2024-02-20 06:12:13

<p>Subgraphs have already proved to be a game-changer for web3 data indexing. A range of applications spanning <a href="https://www.zeeve.io/blog/rise-of-gaming-economy-powered-by-blockchain/">gaming</a>, <a href="https://www.zeeve.io/blog/a-simple-and-comprehensive-guide-on-non-fungible-tokens/">NFTs</a>, <a href="https://www.zeeve.io/blog/banking-the-unbanked-defi-promoting-financial-inclusion/">DeFi</a>, and institutional platforms have been using their own <a href="https://www.zeeve.io/subgraphs/">custom subgraphs</a> for retrieving highly specific data. In our previous articles, we have had in-depth discussions about <a href="https://www.zeeve.io/blog/subgraphs-in-blockchain-benefits-use-cases-deployment/">Subgraph in blockchain</a>, its use cases, deployment walkthroughs, and more. In today’s article, let’s learn about a new and highly useful feature– ‘Webhooks,’ which are now supported on <a href="https://www.zeeve.io/subgraphs/">Zeeve Subgraphs</a> and are enabling next-level real-time data streaming ‘Webhooks.’&nbsp;</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/Empower-Your-Web3-Development-with-custom-Data-Indexers.-1536x195-1-1024x130.jpg" alt="" class="wp-image-59665"/></a></figure>
<h2 class="wp-block-heading" id="h-what-are-webhooks-in-subgraph">What are Webhooks in Subgraph?</h2>
<p>Subgraphs Webhooks is an exciting and very useful feature that allows applications to receive web3 data in real-time, parallel with the indexed data. Webhooks get triggered upon every entity change in the <a href="https://www.zeeve.io/subgraphs/">Subgraph</a>, and it updates the corresponding results immediately. By doing this, webhooks allow subgraphs to push and sync real-time data to databases, allowing the applications to perform important operations like code execution or updating a backend. Webhooks are designed to function in line with your <a href="https://www.zeeve.io/subgraphs/">subgraphs</a>, eliminating the need to manage a separate infrastructure or invest resources in a different Subgraph.&nbsp;</p>
<p>Speaking about the benefits, webhooks in subgraphs allow you to securely stream real-time web3 data, trigger even minor changes in the entity, and keep the data flowing on your application. Many <a href="https://www.zeeve.io/subgraphs/">subgraph providers</a>, including <a href="https://www.zeeve.io/">Zeeve</a>, are now offering webhooks for each of their projects, improving the data flow for a variety of applications. Having access to real-time data is useful for all kinds of applications, be they high- or medium-traction applications. However, note that if you want to track an immutable entity, then subgraph webhooks won’t work in that case, meaning that it won’t update real-time data.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxtkaccxjilmntpa9r8e.png)
<h2 class="wp-block-heading">How Subgraph-driven Webhooks work?</h2>
<p>Webhooks in Subgraph work by sending real-time data results via HTTP Post requests for all the entities in which you have enabled webhooks. So, if a subgraph handler executes a call method like entity.save(), an update is reflected to the intermediate database powering the underlying subgraph API. A real-time watcher then interprets this update and puts it to the webhook handler while enabling a few important operations like UPDATE, INSERT, or DELETE. A Subgraph can store different versions of entities with their block_range column, enabling you to understand the difference between the true entity change or changes occurring due to the reorganization of the blockchain.</p>
<h2 class="wp-block-heading">How to create subgraph webhooks for real-time data streaming?</h2>
<p>There are two main ways to create webhooks for <a href="https://www.zeeve.io/subgraphs/">subgraph</a>– either through the traditional programming method or the low-code approach, which is possible through Zeeve’s Traceye. We will discuss both the methods here:</p>
<h3 class="wp-block-heading">Option-1: The programming way</h3>
<p>To create subgraph webhooks via programming, you will need deployed subgraph(s) for your project, as well as a fully-functioning webhook handler. Following is the step-by-step process to create webhooks:</p>
<ol><!-- wp:list-item -->
<li>At first, you need to deploy one or more subgraphs, as required for your project. Refer to this detailed guide on <a href="https://www.zeeve.io/blog/how-to-deploy-custom-subgraph-with-the-graph-protocol/">custom subgraph deployment.<br></a></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Next, create the webhook handler.Creating a handler from scratch is a complex process. However, for the testing purpose, you can use pre-built webhook handlers like <a href="https://webhook.site/">webhook.site</a>.<br></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Now, create your webhook to receive real-time data on your <a href="https://www.zeeve.io/subgraphs/">subgraph</a>. Below is an example of command that represents webhook creation for a gaming subgraph:</li>
<!-- /wp:list-item --></ol>
<pre class="wp-block-code has-background" style="background-color:#f7f7f7;font-size:16px"><code>subgraph webhook create gaming/v1 --name gaming-event-webhook --entity event --url https://webhook.site/&lt;ANOTHER-UNIQUE-WEBHOOK-URL&gt;
✔ Creating webhook

Webhook 'gaming-event-webhook' created.</code></pre>
<li>Testing your webhook is the final step that you can do by inspecting the custom handler or the webhook.site URL, whichever is applicable for your setup. Your webhook should stream real-time data seamlessly. If not, additional modifications are required on it.&nbsp;</li>
<p>As you can see, this approach involves creating a webhook handler, webhook itself, and then testing– all through programming. This can be complex and resource-intensive at the same time. As an alternative to this, let’s discuss the second option; a low-code approach.</p>
<h3 class="wp-block-heading">Option-2: The Low-code, hassle-free way</h3>
<p>You can opt for the low-code approach offered in Zeeve’s Traceye; a one-click <a href="https://www.zeeve.io/subgraphs/">subgraph deployment</a> and management platform, now supporting no-code creation of webhook. Here’s is the step-by-step process:</p>
<p><strong>Step:1</strong> To deploy your subgraph or to activate webhooks, you first need to buy subgraphs and webhook add ons. For this,, navigate to ‘<a href="https://www.zeeve.io/subgraphs/">Hosted Subgraph</a>’ located at the left panel.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j3v1z9kqn555c58gwq20.png)
<p><strong>Step:2</strong> Proceed with the ‘Buy Subgraph’ option.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zd9nvamopqpeh3irqcbw.png)
<p>As you can see, it will give you the option for webhook addons. Select your preferred quantity and complete the payment process to be able to <a href="https://www.zeeve.io/subgraphs/">deploy your Subgraph</a>. Now, click on webhook to enable them.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kyko4mua8t6huwkmdbfc.png)
<p><strong>Step:3</strong> Start deploying your subgraph on Zeeve’s Traceye. It facilitates a quick, one-click deployment of all your subgraphs and manages them on a highly-optimized, enterprise-grade infrastructure. Refer to the guide linked below for step-by-step process: <a href="https://www.zeeve.io/blog/how-to-deploy-subgraphs-on-zeeve-step-by-step-guide/"><strong>How to deploy Subgraphs with Zeeve?&nbsp;</strong></a></p>
<p><strong>Step:4</strong> Go to your deployed subgraph and click on webhook to enable them.</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ee2u31c7hxpb2sl4zo3w.png)
<p>A new page will appear, asking you to enter Subgraph entities and the webhook URL.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ud4gmz8zexmv1rotf0cg.png)
<p><strong>Step:5</strong> Add Webhook URL and entities of your subgraph. Webhook URL is a post url that will receive the real-time data. You can easily create this url by using services like Webhook.site, Webhook Tester, and TypedWebhook.tools. Regarding entities, these represent the table you create in the GraphQL schema. For example, the first table in the below image has ‘Approval’ as entity, second one has ‘ApprovalForAll’, and the third has ‘Creditcleared’. Similarly, you can add entities from your subgraph schema.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qaz7viomcr15xypshlm4.png)
<p>After adding the details, click on continue and your Subgraph webhooks will be created and it will start streaming real-time data right away.</p>
<p><strong>Step:6</strong> Navigate to Webhooks, and you will see a tabular dashboard that records all the information about your webhooks, such as Entity, URL, Webhook Status, Delivered records, and Undelivered records. This helps you to keep a track of how your webhooks perform and if there’s an issue that needs to be fixed.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxhmonuwy4ygsc290dnm.png)
<p>Further, the <a href="https://www.zeeve.io/subgraphs/">Zeeve Subgraph</a> webhook gives you the flexibility to delete your webhooks in just one click. From the same page showing information about your webhooks, select all the entities you want to delete and click ‘Delete’. Continue with yes, and your webhooks will be deleted successfully.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vikm3sr7hselzse9ih4u.png)
<p>We have successfully enabled webhooks in subgraph. As we can see, it was quick, simple, and did not require writing even a single line of code. Everyone, whether having technical skills or not– they can <a href="https://www.zeeve.io/subgraphs/">deploy subgraph</a> and enable webhook with <a href="https://www.zeeve.io/">Zeeve</a> without any complexity and at significantly lower cost, resulting in faster time to market.&nbsp;</p>
<h2 class="wp-block-heading">Conclusion</h2>
<p>Webhooks in Subgraph is a relatively new concept, which is getting traction because of its exciting capabilities of streaming real-time blockchain data, thereby simplifying the web3 application development and the experience for end users. Knowing this, Zeeve Traceye started supporting the webhook feature, and now it is open available for anyone to use.&nbsp;</p>
<p>Further, if you want, <a href="https://www.zeeve.io/">Zeeve</a> offers to create a <a href="https://www.zeeve.io/subgraphs/">custom subgraph</a> from scratch that will cater to the specific data needs of your project. Contact us for more details about how <a href="https://www.zeeve.io/subgraphs/">Zeeve subgraph service</a> will benefit your web3 application and what all blockchain-related services <a href="https://www.zeeve.io/">Zeeve</a> offers. If you have any queries, you can drop them on this page, or for a detailed discussion, <a href="https://www.zeeve.io/talk-to-an-expert/">schedule a call with us</a>.&nbsp;</p>