> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mycryptoserver.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Inngest Setup

> Configure Inngest for durable payment workflows

[Inngest](https://www.inngest.com) runs the durable workflows that power the payment lifecycle. Instead of cron jobs or long-running workers, Inngest provides event-driven step functions that survive server restarts, network failures, and cold starts.

## Why Inngest

Without Inngest, you'd need:

* A polling cron to check pending sessions
* A background worker for payment verification
* A retry queue for webhook delivery

Inngest replaces all of these. The app defines 5 functions; Inngest manages their execution.

## The 5 functions

| Function             | Trigger             | What it does                                                 |
| -------------------- | ------------------- | ------------------------------------------------------------ |
| `sessionLifecycle`   | `session/created`   | Subscribes address to Alchemy, sleeps until expiry           |
| `paymentVerify`      | `payment/detected`  | Waits for confirmations, finalizes the session, runs sweep   |
| `webhookDeliver`     | `session.paid` etc. | POSTs event to merchant webhook endpoint, retries on failure |
| `reconcileAlchemy`   | Hourly cron         | Re-syncs Alchemy watchlists; catches missed webhooks         |
| `cleanupIdempotency` | Daily cron          | Removes expired idempotency cache entries                    |

## Getting started

1. Create a free account at [app.inngest.com](https://app.inngest.com).
2. Create a new project.
3. Go to **Manage → Event Keys** and copy your **Event Key**.
4. Go to **Manage → Signing Keys** and copy your **Signing Key**.

## Environment variables

```env theme={null}
INNGEST_EVENT_KEY=your-event-key
INNGEST_SIGNING_KEY=your-signing-key
```

Without these, the app runs in local dev mode (uses `pnpm inngest:dev`) and won't connect to Inngest Cloud.

## Registering the app

After your first Vercel deployment:

1. In the Inngest dashboard, click **Add app**.
2. Enter your app URL: `https://your-app.vercel.app/api/inngest`
3. Inngest will discover all 5 functions automatically.

Every subsequent Vercel deployment re-registers the functions — no manual step needed.

## Pricing

Inngest charges per step. One complete payment flow uses approximately 4 steps:

* 1 step in `sessionLifecycle` (subscribe address + sleep)
* 1–2 steps in `paymentVerify` (verify + finalize)
* 1 step in `webhookDeliver` (deliver event)

The free tier includes \~50,000 steps/month — enough for roughly 12,000 payments.

## Local development

For local development, start the Inngest dev server alongside the web app:

```bash theme={null}
# Both together (recommended)
pnpm dev:all

# Separate terminals
pnpm dev          # web app on :8256
pnpm inngest:dev  # Inngest UI on :8288
```

Visit `http://localhost:8288` to see function runs, replay events, and debug workflows.

## Recovery after an outage

If Inngest is unavailable during active sessions, re-emit lifecycle events after it recovers:

```bash theme={null}
pnpm inngest:resync
```

This re-emits `session/created` events for all in-flight sessions. Each event is deduplicated by `session-{id}` so running it multiple times is safe.
