Webhook
Setting Up Subs Webhooks with Moralis or just listen
Last updated
Setting Up Subs Webhooks with Moralis or just listen
Last updated
Webhooks offer a powerful way to automate reactions to specific events on the blockchain, enhancing the functionality and interactivity of applications. In the context of Subs, webhooks can be utilized to monitor subscription events and any custom actions that are pivotal to subscription management and analytics.
Webhooks, in essence, are automated messages sent from apps when something happens. They have URLs, making them web-accessible for receiving data immediately. Unlike typical APIs where you need to poll for data frequently, webhooks deliver data as it happens, ensuring real-time updates.
Notifications: Alerting users or administrators about subscription renewals, cancellations, or payment issues.
Analytics: Gathering data on user interactions and subscription trends for better business insights.
Compliance: Automatically tracking and reporting for regulatory compliance and auditing.
Integration: Seamlessly connecting your Subs data with other tools and services for enhanced functionality.
Just click on "Require users email address" and add your webhook url.
The following sections will illustrate how to set up Subs webhooks using Moralis’ Streams API.
You have two options for building your stream and receiving Subs webhooks on supported networks:
Via Moralis’ Admin Panel – The second alternative is to create streams using Moralis’ web UI. In this tutorial we will only use the second option
After login, create your stream :
After click on create stream, at the bottom of the page, you will have this view
Tag is just a way for you to identify your stream. After adding your tag, click continue.
Choose the chains you have your subs apps on and continue
Click on Live blocks and Launch Live Blocks , after that, subscribe to your app on Subs page to see if your stream work, if yes, you will have a response in the live playground if not, the playground will be empty. Don't forget to test your filter by testing a not filtered app and your filtered app.
Maybe you want to have your own in-house solution and not depend on a third-party service. You can just listen to the subs contract to see what's going on and make action. Here is an sample code to listen and make action when user subscribe to your app with ethersjs.
Add your chain rpc url
Add subs contract address
Add the app ID for filter your app
Integrating webhooks into your Subs-powered application allows for real-time monitoring and handling of subscription lifecycle , payment confirmations, and any custom blockchain events that you define within your subscription logic. This enables automated workflows, such as:
That's all. After each subscription, Subs will send you all the data relating to that subscription
Here is all type of data Subs will sent after user subscription, cancellation or other actions.
Programmatically – The first alternative is to set up streams programmatically through the use of Moralis’ SDK or API - see an example
Before start creating your stream, login on Moralis
Here, you'll need to choose what subs event you want to listen as webhook, most of the time it will be for new subscription on your app, but maybe also others. You can see all Subs events abis . In this example we'll use the NewSubscription event, so copy and paste it in custom onglet. After that, click on NewSubscription and add your filter with your app ID. You can find your app ID on your app page here for or .
We recommend you to create two apps on subs before testing your stream because sometimes the filter can have problems and your stream can end up listening to all the apps on Subs . If you ever encounter this problem, edit your stream and at the bottom of the page, click on Swith to legacy, reconfigure your app in legacy mode, it should work normally.
Here you will need to add Subs contract address, you can find Subs testnet contract addresses and for mainnet . Be sure to take your supported chain contract address. After copy and paste it, click to continue.
Recommend you to test it fast with . Copy and paste your unique url. Click verify and after deploy your stream. After testing with webhook-site, you can edit the stream to change the webhook and work with yours.
Also notice that Moralis will send you two notifs per block, read more
That's all, you've just set up your subs webhook with moralis
Thanks for your reading, see you