Start / Quickstart

Quickstart

From zero to your first indexed table. Follow along in your terminal.

~2 min5 commandsno key to read
1

Install the CLI

One global binary; works with bun, npm, or pnpm.

terminal
$ bun add -g @secondlayer/cli
2

Set up the one-box

One guided command: secrets, docker-compose + .env written for you, the stack brought up, and verified history restored from the archive instead of syncing from genesis. Your API is live at http://127.0.0.1:3800 — loopback reads need no token; setup prints the INSTANCE_TOKEN export for writes.

terminal
$ secondlayer setup
3

Create from your contract

Infers schema, triggers, and handler from the contract's observed print events, into one file ready to edit or deploy as-is.

terminal
$ secondlayer subgraphs create my-balances --from-contract SP....my-contract
4

Deploy it

Indexes forward from the chain tip and keeps the table live as new blocks arrive; with bootstrapped history it backfills from genesis.

terminal
$ secondlayer subgraphs deploy subgraphs/my-balances.ts
5

Read it back

Rows serve from your instance the moment the first block lands. Same read from the SDK — sl.subgraphs.rows("my-balances", "balances").

terminal
$ curl http://127.0.0.1:3800/v1/subgraphs/my-balances/balances
That’s a live table.

Next: write your first handler, or wire up push delivery.