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 chainabitWhat the demo does
- Registers a
chainabitadapter in the connector registry viaregisterConnectorAdapter. - Verifies the service token by calling
adapter.verify(token)— confirms the granted scopes. - Dispatches a
lens.publishedevent payload to the configured webhook endpoint.
Exit codes:
| Code | Meaning |
|---|---|
0 | All steps succeeded |
1 | Missing env vars |
2 | Token verification failed |
3 | Dispatch failed (network/HTTP error) |
Files
| File | Purpose |
|---|---|
src/adapter.ts | Wraps HttpConnectorAdapter to produce a ConnectorAdapterV1 |
src/index.ts | Runnable demo flow |
.env.example | Required env vars (token + endpoint) |
Token rotation
bash
lenserfight connectors rotate chainabitThe 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:
- Replace the metadata in
src/adapter.tswith your own slug, name, and scope set. - Wire the registration at your service's startup, not in a one-shot script.
- Persist the service token in your secrets manager rather than
.env. - Add retries at the dispatch site if your downstream system has transient failures (the adapter itself should not retry — surface failures as
ok: false).