CLI
March 10, 2026
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 setupsl 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 logoutStreams
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-transfersCodegen
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.tsLocal 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