The sl command manages streams, views, auth, code generation, and local development infrastructure from the terminal. One binary, every Second Layer operation.

Install globally with bun add -g @secondlayer/cli.


Install

bun add -g @secondlayer/cli

# Verify
sl --version

# Interactive setup — network, auth, node config
sl setup

sl setup walks you through network selection (local, testnet, mainnet), authentication via magic link, and optional Stacks node configuration.


Auth

Login with your email via magic link. The CLI creates a cli-<hostname> API key and stores it in ~/.secondlayer/config.json. Session tokens are never persisted.

# Login — sends magic link, creates API key
sl auth login

# Check current auth
sl auth status

# Rotate API key (revoke old + create new)
sl auth rotate

# Manage keys
sl auth keys list
sl auth keys create --name "deploy"
sl auth keys revoke <id>

# Logout — revokes key server-side
sl auth logout

Streams

Scaffold, register, and manage event streams from the CLI.

# Scaffold a new stream config
sl streams new my-stream

# Register with the API
sl streams register streams/my-stream.json

# List streams (optionally filter by status)
sl streams ls
sl streams ls --status active

# Get stream details
sl streams get <id>

# Enable / disable
sl streams set <id> enable
sl streams set <id> disable

# View delivery logs (--follow for real-time)
sl streams logs <id>
sl streams logs <id> --follow

# Replay a block range (max 10,000 blocks)
sl streams replay <id> --start 150000 --end 160000

# Rotate webhook secret
sl streams rotate-secret <id>

# Delete (with confirmation)
sl streams delete <id>

Views

Deploy and manage indexed views. The CLI bundles handler code with esbuild, diffs schema changes, and handles deployment.

# Scaffold a new view
sl views new token-transfers

# Deploy to Second Layer
sl views deploy views/token-transfers.ts

# Dev mode — watches for changes, hot-redeploys
sl views dev views/token-transfers.ts

# Check indexing status and health
sl views status token-transfers

# Query a deployed view
sl views query token-transfers transfers --sort _block_height --order desc
sl views query token-transfers transfers --filter sender=SP1234... --limit 25
sl views query token-transfers transfers --filter "amount.gte=1000000" --count

# Reindex from scratch or a specific range
sl views reindex token-transfers
sl views reindex token-transfers --from 150000 --to 160000

# Scaffold a view from a deployed contract's ABI
sl views scaffold SP1234...::my-contract --output views/my-contract.ts

# Generate a typed client from a deployed view
sl views generate token-transfers --output src/generated/

# Delete view and all data
sl views delete token-transfers

Codegen

Generate TypeScript interfaces from Clarity contracts. Supports local .clar files and deployed contract addresses. Works with the plugin system for React hooks, testing utilities, and transaction actions.

# Initialize config file
sl init

# Generate types from config
sl generate

# Generate from specific files
sl generate contracts/my-contract.clar

# Watch mode — regenerate on file change
sl generate --watch

# Specify output path
sl generate --output src/generated/contracts.ts

Local dev

Run the full Second Layer stack locally for development. Manages the API, indexer, worker, webhook receiver, and optionally a Stacks node — all via Docker.

# Start all services
sl local start

# Check status
sl local status

# View logs (with service filtering)
sl local logs --service indexer

# Manage local Stacks node
sl local node setup
sl local node start
sl local node logs
sl local node stop

# Start/stop the full stack (node + services)
sl stack start
sl stack stop

# Inspect indexed data
sl db blocks
sl db txs --limit 20
sl db events
sl db gaps

# Sync missing blocks
sl sync --from 150000 --to 160000
sl sync --gaps

# System diagnostics
sl doctor

# Stop everything
sl local stop

Commands

Core
sl setupInteractive onboarding
sl statusSystem health — DB, queue, indexing, streams
sl whoamiCurrent authenticated account
sl doctorDiagnostic check (local + hosted)
sl initCreate secondlayer.config.ts
Auth
sl auth loginMagic link → API key
sl auth logoutRevoke key + clear config
sl auth statusShow key, email, plan
sl auth rotateRevoke + create new key
sl auth keys [list|create|revoke]Key management
Streams
sl streams new <name>Scaffold stream config
sl streams register <file>Register from JSON file
sl streams lsList all streams
sl streams get <id>Stream details
sl streams set <id> <state>Enable / disable stream
sl streams logs <id>Delivery log (--follow)
sl streams replay <id>Replay block range
sl streams rotate-secret <id>New webhook secret
sl streams delete <id>Delete stream
Views
sl views new <name>Scaffold view definition
sl views deploy <file>Deploy (local or remote)
sl views dev <file>Watch + hot-redeploy
sl views status <name>Indexing status + health
sl views query <name> <table>Query with filters, sort, count
sl views reindex <name>Reindex (--from, --to)
sl views scaffold <contract>Generate view from ABI
sl views generate <name>Generate typed client
sl views delete <name>Delete view + data
Codegen
sl initCreate config file
sl generate [files...]Generate TS from Clarity contracts
Database
sl db blocksRecent indexed blocks
sl db txsRecent transactions
sl db eventsRecent events
sl db gapsGaps in indexed data
sl db resetTruncate all indexed data
sl syncFetch + index missing blocks
Config
sl config showPrint current config
sl config set <key> <value>Set config value (dot notation)
sl config resetReset to defaults
Local
sl local start / stop / restartDev services lifecycle
sl local statusEnvironment status
sl local logsService logs (--service filter)
sl local node [setup|start|stop|logs]Stacks node management
sl stack start / stopFull stack (node + services)
sl webhook init <dir>Scaffold webhook handler