A TypeScript Express.js webhook server that listens for events from your Fordefi organization and processes transaction data.
- Node.js 18+
- npm or yarn
- Fordefi API User Token - Get your token here
- Fordefi Public Key - Download from webhook docs
-
Clone and navigate
cd api-examples/typescript/webhooks -
Install dependencies
npm install express axios dotenv npm install -D typescript @types/express @types/node ts-node nodemon
-
Initialize TypeScript config
npx tsc --init
-
Environment Variables
Create a.envfile:FORDEFI_API_USER_TOKEN=your_fordefi_api_token_here PORT=8080
-
Public Key Setup
Download the Fordefi public key and save it aspublic_key.pemin the same directory:# Download from: https://docs.fordefi.com/developers/webhooks#validate-a-webhook # Save as: public_key.pem
-
Package.json Scripts
Add these scripts to yourpackage.json:{ "scripts": { "dev": "nodemon --exec ts-node app.ts", "build": "tsc", "start": "node dist/app.js" } }
npm run devnpm run build
npm startnpx ts-node app.ts| Method | Endpoint | Description |
|---|---|---|
POST |
/ |
Main webhook endpoint for Fordefi events |
- Signature Verification - Validates X-Signature header using ECDSA P-256
- Event Processing - Parses webhook payload and extracts transaction ID
- Data Fetching - Retrieves full transaction data from Fordefi API
- Response - Returns transaction data or success message
{
"id": "transaction_id_here",
"status": "completed",
"blockchain": "ethereum",
"type": "transfer",
// ... additional transaction data
}-
Install ngrok
# Install ngrok: https://ngrok.com/download -
Start your webhook server
npm run dev
-
Expose locally with ngrok
ngrok http 8080
-
Configure Fordefi Webhook
- Go to Fordefi Console → Settings → Webhooks
- Add webhook URL:
https://your-ngrok-url.ngrok.io/ - Save and test
webhooks/
├── app.ts # Main application file
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .env # Environment variables
├── public_key.pem # Fordefi public key
└── README.md # This file
| Variable | Required | Description |
|---|---|---|
FORDEFI_API_USER_TOKEN |
Yes | Your Fordefi API access token |
PORT |
No | Server port (default: 8080) |
📚 Documentation Links: