Skip to content

Chainabit Reference Example

examples/connectors/chainabit-example/ is the canonical reference adapter — a minimal Node.js project that demonstrates the full lf connectors add → register → verify → dispatch lifecycle in under 100 lines.

Run it

bash
cd examples/connectors/chainabit-example
cp .env.example .env

# 1. Register the connector and capture the service token
lenserfight connectors add chainabit \
  --name "Chainabit Reference" \
  --slug chainabit \
  --scopes lenses:read

# Paste the printed service_token into .env → LENSERFIGHT_SERVICE_TOKEN
# Set LENSERFIGHT_CONNECTOR_ENDPOINT to a webhook target you control

# 2. Run the demo
pnpm install
pnpm demo

# 3. Verify reachability via the CLI
lenserfight connectors test chainabit

What the demo does

  1. Registers a chainabit adapter in the connector registry via registerConnectorAdapter.
  2. Verifies the service token by calling adapter.verify(token) — confirms the granted scopes.
  3. Dispatches a lens.published event payload to the configured webhook endpoint.

Exit codes:

CodeMeaning
0All steps succeeded
1Missing env vars
2Token verification failed
3Dispatch failed (network/HTTP error)

Files

FilePurpose
src/adapter.tsWraps HttpConnectorAdapter to produce a ConnectorAdapterV1
src/index.tsRunnable demo flow
.env.exampleRequired env vars (token + endpoint)

Token rotation

bash
lenserfight connectors rotate chainabit

The previous token is revoked immediately — replay attempts return 401. Update LENSERFIGHT_SERVICE_TOKEN and re-run pnpm demo.

Adapt for your own service

The example deliberately stays minimal. To productionize:

  1. Replace the metadata in src/adapter.ts with your own slug, name, and scope set.
  2. Wire the registration at your service's startup, not in a one-shot script.
  3. Persist the service token in your secrets manager rather than .env.
  4. Add retries at the dispatch site if your downstream system has transient failures (the adapter itself should not retry — surface failures as ok: false).

See also