Tools

Read secondlayer://context first, then any other resource you need, before calling tools.

ResourceWhat it returns
secondlayer://chain-triggersChain-webhook trigger types and the filter fields each accepts.
secondlayer://column-typesSubgraph column types, SQL mappings, and options
secondlayer://contextLive agent context — what exists (your subgraphs, webhooks, account), what you can do, and read-auth tiers.
secondlayer://filtersEvent filter types and their available fields
secondlayer://traitsSIP trait standards the platform can classify and scaffold against — the valid values for contracts_find `trait`.
secondlayer://samples/{contractId}Decoded camelCase print samples for a contract (schema + up to 5 events).

For Index, call contracts_find and index_print_schema first to learn what a contract emits.

Reads are cursor-paginated. The server stays at 20 tools or fewer; create, update, replay and other admin verbs are secondlayer <noun> ... --json in the CLI. Account tools register only when SECONDLAYER_API_URL is the hosted API.

Subgraphs

ToolWhat it does
subgraphs_deployDeploy a subgraph from TypeScript code. Local only.
subgraphs_listList all deployed subgraphs.
subgraphs_queryQuery rows from a subgraph table (max 200 rows), reading the open /v1 surface — { rows, next_cursor, tip } envelope, cursor-paginated (no offset).
subgraphs_statusGet full details of a subgraph including schema, health (incl. health.emptyMapping when processed events wrote 0 rows), and table columns.
subgraphs_testProve a subgraph mapping writes rows against Index data before deploy. Local only.

Webhooks

ToolWhat it does
webhooks_deliveriesList recent delivery attempts for a webhook — status code, attempt count, error, duration, timestamps.
webhooks_listList all webhooks for the current account.

Index

ToolWhat it does
batch_queryRun up to 10 public /v1 reads in one round trip (POST /v1/batch).
index_eventsList chain events from the Index by event type.
index_print_schemaEmpirical per-topic print payload schemas for a contract, inferred from sampled on-chain events: each topic's fields with observed Clarity types, decoded TS types, subgraph column types, and presence rates.
index_rune_activityList Bitcoin Runes etch, mint, transfer, and burn events.
index_rune_balancesList current Bitcoin Runes balances per unspent output.
index_runesList the Bitcoin Runes catalog: identity, supply, mints, and mint terms.
index_state_writesList the exact contract-state writes each block committed, in node order: {block_height, ordinal, tx_index, key, value_hex}.

Streams

ToolWhat it does
streams_tipCurrent canonical chain tip as Streams sees it: block height/hash, burn height, finalized_height, lag_seconds, and the oldest seekable height/cursor for this key's retention window.

Contracts

ToolWhat it does
contracts_findDiscover deployed Stacks contracts conforming to a trait (e.g. "sip-010", "sip-009", "sip-013").
contracts_get_abiFetch a single deployed contract's ABI from the registry (prod-safe).

Proofs

ToolWhat it does
proofs_inspectProof inventory for one Stacks block: the state writes the block committed (not checked here) and the free /v1/proofs routes that serve every byte.

Account

ToolWhat it does
account_whoamiShow the archive account email at api.secondlayer.tools, not the self-host instance. Hosted only.
billing_statusRead-only credits state for the account at api.secondlayer.tools: prepaid balance, this month's spend, auto-refill config, this month's usage and the 24h burn rate. Hosted only.
  • Cursors are opaque and per keyspace: contract-call cursors are not interchangeable with event cursors.
  • For subgraph tables, every page with rows returns next_cursor: poll with cursor = next_cursor ?? cursor to tail without streaming.
  • The underlying endpoints: API reference.
Edit on GitHub

Quick Start

Copy this prompt into your agent.

Set up Secondlayer Index in this project. It reads Stacks chain data, decoded, from block 1.

1. Install `@secondlayer/sdk` with the project's package manager. If a release-age policy blocks the install, stop and ask me instead of changing it.
2. Ask me for a Secondlayer API key (`sk-sl_...`, from https://www.secondlayer.tools/signin) and put it in `.env` as `SECONDLAYER_API_KEY`. Never commit it. If I self-host, use `INSTANCE_TOKEN` and my instance URL instead. Until I give you one, read with a free trial key: `curl -X POST https://api.secondlayer.tools/api/public/trial-key` returns `{ key }`, read-only for Streams and Index, good for 24 hours and 100,000 rows. Keep it out of git too.
3. Add a note to `AGENTS.md`, creating it if needed: before using Secondlayer, follow the secondlayer skill if it's installed, and read https://www.secondlayer.tools/llms.txt. Before writing code, read https://www.secondlayer.tools/docs/index.md. Any docs page opens as Markdown when you add `.md` to its URL.
4. If you support skills, run: `bunx skills add ryanwaits/secondlayer --skill secondlayer -y`