Back to APIs

Bitcoin Lightning Network nanotransactions with events, callbacks, and webhooks.

Using the ZBD API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your ZBD background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Example code using ZBD

Below is a working code example of how you can use ZBD with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
import { z } from "zod";
3
4
// This code integrates the ZBD API to facilitate Bitcoin payments to ZBD usernames.
5
// To use this integration, you need to create a ZBD project, which provides a unique API key
6
// and a Bitcoin Lightning wallet. With this API key, you can programmatically handle Bitcoin
7
// transactions, including receiving funds, making payments, and withdrawing Bitcoin.
8
// Learn how to create a project: [Create a project](https://zbd.dev/docs/dashboard/projects/create)
9
// Detailed instructions for using the API key: [API Key Usage](https://zbd.dev/docs/dashboard/projects/api)
10
11
client.defineJob({
12
id: "pay-to-zbd-username",
13
name: "Pay BTC to ZBD username",
14
version: "1.0.0",
15
trigger: eventTrigger({
16
name: "zbd.pay.username",
17
schema: z.object({
18
amount: z.number(), // The amount for the Payment in millisatoshis
19
gamertag: z.string(),
20
description: z.string().optional(),
21
}),
22
}),
23
24
run: async (payload, io, ctx) => {
25
// Wrap any ZBD API call in io.runTask so it's resumable and displays in logs
26
await io.runTask(
27
"Send sats to username",
28
async () => {
29
const options = {
30
method: "POST",
31
headers: {
32
apikey: process.env.ZBD_API_KEY!,
33
"Content-Type": "application/json",
34
},
35
body: `{"amount":"${payload.amount}","gamertag":"${payload.gamertag}","description":"${payload.description}"}`,
36
};
37
38
const response = await fetch(
39
`${process.env.ZBD_BASE_URL}/v0/gamertag/send-payment`,
40
options
41
);
42
return response.json();
43
},
44
45
// Add metadata to improve how the task displays in the logs
46
{ name: "Pay BTC to ZBD Username", icon: "zbd" }
47
);
48
},
49
});