Verifying a webhook payload
Listen for events to automatically trigger reactions.
Webhook payloads must be verified before they are trusted and used on your server. This is done by verifying a signature sent with your webhook.
Your endpoint must return a 2xx (status code 200-299) response for the webhook to be marked as delivered. Any other statuses (including 3xx) are considered failed deliveries.
Using Openfort Node SDK#
Use the Openfort SDK's constructWebhookEvent
method to verify an incoming webhook. Pass in the request body and the signature header. As an example, you can verify a webhook using the code below:
_25app.post(_25 '/webhook',_25 express.raw({ type: 'application/json' }),_25 async (req: Request, _res: Response) => {_25 const openfort = new Openfort('OPENFORT_SECRET_KEY')_25 try {_25 const event = await openfort.constructWebhookEvent(_25 req.body.toString(),_25 req.headers['openfort-signature']_25 )_25 switch (event.type) {_25 case "transaction_intent.succeeded":_25 console.log(`TransactionIntent ID: ${event.data.id}`)_25 break_25 case "transaction_intent.failed":_25 console.log(`TransactionIntent ID: ${event.data.id}`)_25 break_25 default:_25 console.log(`Unhandled event type ${event.type}`);_25 }_25 } catch (e) {_25 console.error((e as Error).message)_25 }_25 }_25)
Webhook object#
The webhook object contains the following fields:
_10{_10 "data": {_10 "id": "tin_c502d628-5bb3-42f2-b8f5-62ba4d71df3a",_10 "createdAt": 1689869074,_10 "object": "transactionIntent",_10 "etc":"..."_10 },_10 "type": "transaction_intent.succeeded",_10 "date": 1689869074_10}
Where the type
will be one of the following:
transaction_intent.succeeded
: The transaction intent has arrived on-chain and is confirmed.transaction_intent.failed
: The transaction intent has arrived on-chain and is reverted.transaction_intent.cancelled
: The transaction intent parameters were not met.transaction_intent.broadcast
: The transaction intent was broadcasted.balance. project
: The project balance.balance.contract
: The contract balance.balance.dev_account
: The balance of your backend wallet.
The data
will be a transaction intent object.