Back to Integrations
Edge Function

Herald + Cloudflare Worker

Run Herald notification logic at the edge with Cloudflare Workers. Handle governance broadcasts and incoming webhooks directly on Cloudflare's global network — with zero cold starts, sub-millisecond latency, and the Worker's env-binding pattern for API key management.

Ready to ship?

Start sending zero-PII notifications in minutes.

REGISTER YOUR WALLET
ZK-SECURE SOLANA NATIVE

Package: @herald-protocol/sdk

Install: npm install @herald-protocol/sdk

View full example on GitHub →

Worker Entry Point

Fetch handler dispatching to governance and webhook routes.

Source →
Cloudflare Worker / Worker Entry Point
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Herald } from '@herald-protocol/sdk';
export default {
async fetch(req: Request, env: Env): Promise<Response> {
const url = new URL(req.url);
if (url.pathname === '/api/governance' && req.method === 'POST') {
return handleGovernance(req, env);
}
if (url.pathname === '/api/webhooks/herald' && req.method === 'POST') {
return handleWebhook(req, env);
}
return new Response('Not found', { status: 404 });
},
};
interface Env {
HERALD_API_KEY: string;
HERALD_WEBHOOK_SECRET: string;
}
async function handleGovernance(req: Request, env: Env): Promise<Response> {
const herald = new Herald({ apiKey: env.HERALD_API_KEY });
const { title, voters } = await req.json();
if (!voters?.length || !title) {
return Response.json({ error: 'voters and title required' }, { status: 400 });
}
const result = await herald.notifyBulk({
wallets: voters,
subject: `🗳 New Proposal: ${title}`,
body: `A new governance proposal has been published.\nCast your vote on the DAO dashboard.`,
category: 'governance',
receipt: true,
idempotencyPrefix: `gov_${Date.now()}`,
});
return Response.json(result, { status: 202 });
}
async function handleWebhook(req: Request, env: Env): Promise<Response> {
const signature = req.headers.get('x-herald-signature');
const payload = await req.json();
const rawBody = JSON.stringify(payload);
if (!signature || !env.HERALD_WEBHOOK_SECRET) {
return Response.json({ error: 'Missing signature or secret' }, { status: 401 });
}
const isValid = await Herald.verifyWebhookSignature(rawBody, signature, env.HERALD_WEBHOOK_SECRET);
if (!isValid) {
return Response.json({ error: 'Invalid signature' }, { status: 401 });
}
console.log(`[Webhook] ${payload.event}: ${payload.notificationId}`);
return Response.json({ received: true });
}

Common Patterns

Edge governance broadcast with env bindings
Edge webhook verification and dispatch
Zero-cold-start notification delivery
Sub-millisecond signature verification

Start building with Herald

Clone the examples repo, copy the code that fits your stack, and deploy.