π§΅ Send Transaction and Receive Notification via Webhook
This guide documents the full workflow for sending a blockchain transaction and receiving asynchronous status updates via webhook events. It covers how to subscribe to the necessary events and how to interpret transaction outcomes (mined or failed).
π Objective: Ensure clients can programmatically send transactions and handle outcomes via webhook notifications.
π OpenAPI Documentationβ
β¨ Workflow Summaryβ
This workflow includes the following steps:
- πΉ Subscribe to webhook events for TX_MINED and TX_FAILED.
- πΉ Send a blockchain transaction (e.g. minting an ERC3643 token).
- πΉ Receive asynchronous notification via webhook on transaction success or failure.
π Workflow Steps Tableβ
| Step | API Operation | Method | Parameters | Outputs | Description |
|---|---|---|---|---|---|
| Subscribe to All TX Events | POST /subscriptions/webhooks | - | eventTypes, callbackUrl | subscriptionId | Subscribes to TX_MINED and TX_FAILED for all transactions by the client |
| OR: Subscribe by Token | POST /tokens/{tokenId}/subscriptions/webhook | - | tokenId, eventTypes, callbackUrl | subscriptionId | Subscribes to TX_MINED and TX_FAILED for a specific token only |
| Mint Token (example tx) | POST /erc3643/{tokenId}/mint | - | recipient, amount, tokenId | transactionId | Sends a token mint transaction |
| Receive Webhook Event | Callback to callbackUrl | - | eventType, txHash, status | - | Event TX_MINED or TX_FAILED sent to the registered callback URL |
π¨ Workflow Visualizationsβ
π Mermaid Sequence Diagramβ
π Step-by-Step Implementationβ
Step 1: Subscribe to Webhook Eventsβ
Choose between global subscription (all transactions) or token-specific subscription.
Option A: Global Subscription (Recommended)β
Subscribe to all transaction events across all tokens for your client.
Endpoint: POST /subscriptions/webhooks
Request Body:
{
"event": "TX_MINED",
"callbackUrl": "https://your-server.com/webhooks/blockchain"
}
Request Parameters:
eventTypes: Event type to subscribe tocallbackUrl: Your server endpoint that will receive webhook notifications
Response:
{
"id": "sub_123e4567-e89b-12d3-a456-426614174000",
"event": "TX_FAILED",
"callbackUrl": "https://your-server.com/webhooks/blockchain"
}
Option B: Token-Specific Subscriptionβ
Subscribe to events for a specific token only.
Endpoint: POST /tokens/{tokenId}/subscriptions/webhook
Path Parameters:
tokenId: UUID of the specific token
Request Body:
{
"event": "TX_FAILED",
"callbackUrl": "https://your-server.com/webhooks/token-events"
}
Response:
{
"id": "sub_456e7890-e89b-12d3-a456-426614174111",
"event": "TX_FAILED",
"callbackUrl": "https://your-server.com/webhooks/token-events"
}
Step 2: Send a Blockchain Transactionβ
Execute any blockchain transaction (using mint as an example).
Endpoint: POST /erc3643/{tokenId}/mint
Request Body:
{
"to": ["0x1234567890abcdef1234567890abcdef12345678"],
"amount": ["1000000000000000000"]
}
Request Parameters:
to: Array of recipient addresses (must have valid identity)amount: Amounts in wei (1 token = 10^18 wei for 18 decimals)
Response:
{
"id": "tx_789e0123-e89b-12d3-a456-426614174222"
}
Save the transaction id to correlate with webhook events.
Step 3: Receive Webhook Notificationsβ
Your server will receive POST requests to the callbackUrl specified in Step 1.
TX_MINED Event (Success)β
Received when the transaction is successfully mined on the blockchain.
{
"type": "TX_MINED",
"event": {
"txUUID": "tx_789e0123-e89b-12d3-a456-426614174222",
"txHash": "0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838",
"timestamp": 1634567890
}
}
Event Fields:
txUUID: Your transaction ID from Step 2txHash: Blockchain transaction hash for verificationtimestamp: Unix timestamp of mining
TX_FAILED Event (Failure)β
Received when the transaction fails.
{
"type": "TX_FAILED",
"event": {
"txUUID": "tx_789e0123-e89b-12d3-a456-426614174222",
"reason": "Insufficient balance",
"timestamp": 1634567890
}
}
Step 4: Handle Webhook in Your Serverβ
Implement a webhook handler to process notifications.
π‘ Key Conceptsβ
Webhook vs Pollingβ
Webhooks (Recommended):
- β Instant notifications
- β No API rate limits
- β Reduced server load
- β Better user experience
Polling:
- β Delayed notifications
- β Consumes API quota
- β Increased server load
- β Less efficient
Event Typesβ
- TX_MINED: Transaction successfully confirmed on blockchain
- TX_FAILED: Transaction execution failed
- GAS_USAGE_HIGH: Gas limit warning (80%+ of limit)
- TOKEN_TRANSFER: Token transfer event
- TOKEN_MINT: Token mint event
- TOKEN_BURN: Token burn event
Webhook Securityβ
Always verify webhook authenticity using HMAC signatures to prevent spoofing attacks.
β οΈ Important Notesβ
- HTTPS Required: Webhook callback URLs must use HTTPS in production
- Status Code: Always return 2xx status code for successful processing
- Error Handling: Failed webhooks are retried up to 5 times with exponential backoff
- Signature Verification: Verify HMAC signature on all webhook requests
- Order Not Guaranteed: Events may arrive out of order; use timestamps
π Related Endpointsβ
π Troubleshootingβ
Webhooks Not Receivedβ
If you're not receiving webhooks:
- β Callback URL is accessible from internet (not localhost)
- β Firewall allows incoming POST requests
- β SSL certificate is valid (for HTTPS)
- β Subscription is active (check subscription status)
- β Event types include TX_MINED and TX_FAILED
Webhook Signature Invalidβ
If signature verification fails:
- β Use correct HMAC secret key
- β Include all required headers in signature calculation
- β Use correct hash algorithm (SHA-256)
- β Check for whitespace or encoding issues
- β Refer to HMAC authentication guide
Transaction Status Unknownβ
If transaction status is unclear:
- β Wait for TX_MINED or TX_FAILED webhook
- β Transactions may take 1-5 minutes to mine
- β Check blockchain explorer using txHash
- β Contact support if no webhook after 15 minutes
π Additional Resourcesβ
πΌ Use Case Exampleβ
Token Mint with Webhook Notificationβ
A platform wants to mint tokens and notify users upon completion.
Step 1 - Subscribe to Webhooks:
{
"eventTypes": "TX_MINED",
"callbackUrl": "https://platform.com/api/webhooks"
}
Step 2 - Mint Tokens:
{
"to": ["0x1234567890abcdef1234567890abcdef12345678"],
"amount": ["5000000000000000000"]
}
Response: tx_789abc...
Step 3 - Receive TX_MINED:
{
"type": "TX_MINED",
"event": {
"txUUID": "tx_789abc...",
"txHash": "0xb5c8bd...",
"timestamp": 12345678
}
}