Reference / CLI

CLI

The sl command-line tool — authenticate once, manage subgraphs and subscriptions from your terminal.

bun add -g @secondlayer/cli
sl login                 # authenticate (opens the browser)
sl subgraphs create      # scaffold a subgraph
                         #   --from-contract <id> infers typed print payloads (no login needed)
sl subgraphs deploy      # deploy a subgraph from a config
                         #   --visibility public|private (managed → public, BYO → private)
sl subgraphs publish     # claim the global public name (409 PUBLIC_NAME_TAKEN if claimed)
sl subgraphs unpublish   # make a subgraph private again
sl subgraphs ls          # list your deployments
sl subscriptions create  # wire up a webhook subscription

Every tool shares one session — sign in once and the SDK, CLI, and MCP server all inherit it.

sl context               # headless orientation snapshot

sl context prints a snapshot to orient before acting. It's the CLI counterpart to the MCP secondlayer://context resource agents read before they reach for a tool.

The snapshot covers:

  • Your account
  • The live Streams and Index tips
  • Your subgraphs and subscriptions
  • Any in-flight reindex operations

sl subscriptions create wires a webhook to a subgraph table.

Chain subscriptions use a different surface

Direct chain subscriptions — webhooks on raw chain events with no subgraph — are created over the SDK, REST, or MCP instead. They take a triggers array rather than a table.

sl subgraphs create sbtc-registry \
  --from-contract SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-registry

--from-contract infers each print topic's real payload shape from indexed history (the print-schema endpoint) and writes a typed definition. Anonymous — no login needed.

The generated definition includes:

  • One print_event source per topic with a prints field map (fully typed event.data)
  • A single wide table with per-column "null except on topics: …" comments
  • Pass --table-per-topic for a normalized table per topic instead

sl subgraphs codegen <file> --payloads emits a .d.ts of per-topic payload types (a discriminated union per source) next to the definition.

Payload codegen is print-only

--payloads is incompatible with --target/--models-only/--env — those are ORM-only.

Deploy-time warnings

sl subgraphs deploy also prints advisory warnings when a handler reads an event.data field never observed on-chain for its source's topic — warn-only, never blocks.

sl subgraphs codegen --target prisma|drizzle|kysely generates a typed ORM schema for a subgraph's tables, for BYO-database setups. Works, frozen — see Subgraphs if you need it.

sl devnet / sl local run the pipeline against a local Clarinet devnet. They work but are frozen — no further investment; the supported dev loop is hosted (sl subgraphs createdeploy against a recent block). Run sl devnet --help if you need them.