Webhooks and Status APIs
Listen for updates in mints, edits, collection creations and other async events
Creating NFT collections and minting or editing NFTs are operations that must be sent to a blockchain. Transaction confirmation on the blockchain can take a few seconds, but during network congestion, it may take several minutes. Webhooks and the action status API allow you to stay up to date on the status of these asynchronous operations.
Some cases where you may want to listen to when transactions are confirmed include:
- Notifying your customers via email that their NFT is ready to access
- Updating your database with the NFT id for the user
- Showing in your website that that the mint has been successful
Ways to check the status of an action
Model | Best for | Mechanism |
---|---|---|
Pull (query for updates) | Quick testing | Action Status API |
Push (get notified) | Scalable apps in production | Webhooks |
Webhooks
In this guide, we will use nodejs to create an API endpoint to listen for and parse webhook events:
1. Create an endpoint route
Using a standard nodejs API server, create an endpoint.
2. Configure the endpoint to read and parse webhook events
On this endpoint, modify the code to handle POST requests only. When a POST request comes through, parse the webhook event of the request body. Ensure your webhook listener responds with a 200
status code. Otherwise the webhook may be sent until you acknowledge it.
The snippet below is an example handler that parses webhook events:
Don’t be strict with payload validations as Crossmint may add new fields to the webhooks as products evolve.
Here are some examples of the webhook results (with dummy data):
3. Pre & post processing
Add your pre and post processing logic when setting up your webhook listener. For example, you can call back to your database when a certain id has succeeded or even use Sendgrid or EmailJS to send an email to a recipient when a mint completes.
4. Setting Up Webhooks on the Crossmint Console
Add an endpoint for the event mint.succeeded
by following this guide.
Once completed, you’ll be redirected to the endpoint details page. Here, you can find the signing secret for verifying webhooks and view a table of all triggered webhook events.
The final step is to test the endpoint. To do so, mint one or two NFTs with the API and observe the responses to verify setup success.
Webhook video walkthrough
Was this page helpful?