Power Discord notifications, back-end operations, orderbooks, and more with webhooks for subgraphs. Receive real-time HTTP POST requests to your backends whenever a subgraph indexes a new event. Every project has webhooks enabled by default for free.
Let’s speed-run a simple example of a webhook. We’ll create a webhook that sends a POST request to a URL of your choice whenever a trade occurs on the X2Y2 exchange.
What you’ll need
One or more subgraphs in your project - this can be from community subgraphs, a deployed subgraph, or a no-code subgraph.
A webhook handler; making a fully functional webhook handler is out of scope for this walkthrough so we’ll be using a test platform called Webhook.site.
Use Messari’s x2y2 subgraph to the x2y2 exchange.
> goldsky subgraph deploy x2y2/v1 --from-ipfs-hash Qmaj3MHPQ5AecbPuzUyLo9rFvuQwcAYpkXrf3dTUPV8rRu Deploying Subgraph: ✔ Downloading subgraph from IPFS (This can take a while) ✔ Validating build path ✔ Packaging deployment bundle from /var/folders/p5/7qc7spd57jbfv00n84yzc97h0000gn/T/goldsky-deploy-Qmaj3MHPQ5AecbPuzUyLo9rFvuQwcAYpkXrf3dTUPV8rRu
Create webhook handler
Let’s use a pre-made webhook handler by going to webhook.site and copying the URL. It may look like something like
USE https://webhook.site/<YOUR-UNIQUE-WEBHOOK-SITE-ID> NOT https://webhook.site/#!/<YOUR-UNIQUE-WEBHOOK-SITE-ID>
Any new webhook can be sent to this URL and we’ll be able to see and inspect the request body.
Create a webhook to receive x2y2 trades.
> goldsky subgraph webhook create x2y2/v1 --name x2y2-trade-webhook --entity trade --url https://webhook.site/<YOUR-UNIQUE-WEBHOOK-URL> ✔ Creating webhook Webhook 'x2y2-trade-webhook' created. Make sure calls to your endpoint have the following value for the 'goldsky-webhook-secret' header: whs_01GNV4RMJCFVH14S4YAFW7RGQK
A secret will be generated for you to use in your webhook handler. This secret is used to authenticate the webhook request. You can ignore it for the purposes for this speed run.
Inspect the webhook.site URL (or your custom handler) again, you should see events start to stream in.