secondlayer

v11.8.0
tools.secondlayer/secondlayer Checked 6 hours ago Published 7 days ago

Stacks chain data: contracts, events, transfers, subgraph scaffolds.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

subgraphs_scaffold

Generate a subgraph from observed print events when available; ABI token transfers or public functions only when the contract has never printed. Review the TypeScript, run subgraphs_test until ok: true with written >= 1, read skipped, then subgraphs_deploy. dryRun is DDL only.

ParameterTypeDescription
contractId *stringFully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)
subgraphNamestringOverride the subgraph name (defaults to contract name)

subgraphs_list

List all deployed subgraphs. Returns summary fields only; read rows with subgraphs_query.

subgraphs_status

Get full details of a subgraph including schema, health (incl. health.emptyMapping when processed events wrote 0 rows), and table columns.

ParameterTypeDescription
name *stringSubgraph name

subgraphs_spec

Fetch a subgraph's self-describing spec — the tables, columns, filters, and read URLs a consumer needs, without guessing. `agent` (default) returns the compact JSON schema built for tool use, `openapi` the OpenAPI document for the subgraph's read routes, `markdown` human-readable docs. Read it before writing queries against an unfamiliar subgraph.

ParameterTypeDescription
name *stringSubgraph name
formatstringagent = JSON schema for tool use (default), openapi = OpenAPI JSON, markdown = docs.md

subgraphs_query

Query rows from a subgraph table (max 200 rows), reading the open /v1 surface — { rows, next_cursor, tip } envelope, cursor-paginated (no offset). Filters support operators: "amount.gte": "1000", "sender.neq": "SP...", "name.like": "%token%". Available operators: eq, neq, gt, gte, lt, lte, like. Every page with rows returns next_cursor (null only when empty): pass it back as `cursor` to read the next page. To TAIL new rows (no streaming over MCP), poll with cursor = next_cursor ?? the cursor you sent. Fetch one row by id with {"_id": "<id>"}. The same rows are readable over HTTP at GET /v1/s…

ParameterTypeDescription
name *stringSubgraph name
table *stringTable name
countbooleanIf true, return row count instead of rows
cursorstringResume from a previous response's nextCursor
fieldsstringComma-separated column list to return (e.g. "sender,amount")
filtersobjectColumn filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})
limitnumberMax rows (default 50, max 200)
orderstringSort order
sortstringColumn to sort by

subgraphs_reindex

Reindex a subgraph: drops and rebuilds the whole subgraph from its start block to chain tip. Takes no block range — use subgraphs_backfill to process a specific range. Returns an operationId — check subgraphs_status (health) or the REST operations endpoint to track progress to completion.

ParameterTypeDescription
name *stringSubgraph name

subgraphs_backfill

Backfill a subgraph over a block range. Non-destructive forward fill (does not drop existing data) — unlike subgraphs_reindex, and the only data-fill path for BYO subgraphs (reindex is blocked there). Both blocks required. Returns an operationId — check subgraphs_status (health) or the REST operations endpoint to track progress.

ParameterTypeDescription
fromBlock *integerStart block (inclusive)
name *stringSubgraph name
toBlock *integerEnd block (inclusive)

subgraphs_stop

Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status; check subgraphs_status (health) or the REST operations endpoint to confirm it reaches a terminal state.

ParameterTypeDescription
name *stringSubgraph name

subgraphs_gaps

List indexing gaps (missing block ranges) for a subgraph. Each gap reports start/end/size, reason, and detected/resolved timestamps. Feed an unresolved gap's range into subgraphs_backfill to fill it. Defaults to unresolved gaps.

ParameterTypeDescription
name *stringSubgraph name
limitintegerMax gaps to return
offsetintegerPagination offset
resolvedbooleanFilter by resolved state (omit for unresolved only)

subgraphs_operations

Operation history for a subgraph (deploy/reindex/backfill/stop), newest first — status, block range, progress, and error. THIS IS THE VERIFY CALL: after subgraphs_deploy, subgraphs_reindex, subgraphs_backfill, or subgraphs_stop, poll it with the returned operationId until `status` is terminal (completed/failed/cancelled) before reporting success. Omit operationId for the recent history.

ParameterTypeDescription
name *stringSubgraph name
operationIdstringFetch one operation by id (the operationId returned by reindex/backfill/stop); omit for recent history

subgraphs_delete

Delete a subgraph permanently.

ParameterTypeDescription
name *stringSubgraph name

subgraphs_deploy

Deploy a subgraph from TypeScript code. Pass the full defineSubgraph() source — it will be bundled, validated, and deployed. Optional startBlock overrides the source definition for this deploy. dryRun validates schema/DDL only and does not run handlers — call subgraphs_test first and deploy only when it returns ok: true with written >= 1. Call subgraphs_reindex separately if you need a forced reindex.

ParameterTypeDescription
code *stringTypeScript source code containing a defineSubgraph() call
dryRunbooleanValidate schema/DDL only — does not run handlers. Use subgraphs_test to prove a mapping writes rows.
startBlockintegerOverride the definition startBlock for this deploy

subgraphs_test

Prove a subgraph mapping writes rows against Index data before deploy. Pass full defineSubgraph() source plus a height range. Returns ok/written/tables; EMPTY_MAPPING means events matched but 0 rows were written — read hint for observed event.data keys and do not invent fields. subgraphs_deploy dryRun is DDL only; do not deploy until ok: true with written >= 1.

ParameterTypeDescription
code *stringTypeScript source containing a defineSubgraph() call
fromHeight *integerStart block height (inclusive)
limitintegerMax Index rows per source (default 50, max 200)
toHeightintegerEnd block height (inclusive); default fromHeight+100

webhooks_list

List all webhooks for the current account. Returns summary fields (no secrets).

webhooks_get

Get full detail for a webhook (triggers, auth, retry config, circuit state).

ParameterTypeDescription
id *stringWebhook id

webhooks_create

Create a webhook that fires on raw chain events (set triggers). Returns `signingSecret` ONCE — forward it to the user so they can wire it into their receiver.

ParameterTypeDescription
name *stringHuman-readable name, unique per account
triggers *arrayChain triggers. Each targets a raw chain event/tx; string fields accept `*` wildcards, `trait` scopes to a SIP/trait. Per-type accepted fields: see the secondlayer://chain-triggers resource. Forward-l…
url *stringWebhook URL
authConfigobjectReceiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}
formatstringWire format (default standard-webhooks)

webhooks_update

Patch a webhook (name, url, authConfig, format, retry, timeout, concurrency).

ParameterTypeDescription
id *stringWebhook id
authConfigobjectReceiver auth sent with each delivery (bearer/etc.)
concurrencyinteger
formatstring
maxRetriesinteger
namestringRename the webhook
timeoutMsinteger
urlstring

webhooks_delete

Delete a webhook. Pending outbox rows are cascade-deleted.

ParameterTypeDescription
id *stringWebhook id

webhooks_test

Send a one-off test webhook to a webhook's URL (built for its format, SSRF-guarded). Logged as a delivery row. Returns {ok, statusCode, error, durationMs, deliveryId}.

ParameterTypeDescription
id *stringWebhook id

webhooks_pause

Pause a webhook: stops delivery attempts and stops queueing new ones. Nothing is deleted — resume picks the webhook back up from the tip. Verify with webhooks_get (status).

ParameterTypeDescription
id *stringWebhook id

webhooks_resume

Resume a paused webhook (also clears a tripped circuit breaker). Deliveries restart from the current tip — use webhooks_replay for the blocks missed while paused. Verify with webhooks_get (status).

ParameterTypeDescription
id *stringWebhook id

webhooks_rotate_secret

Rotate a webhook's signing secret. Returns the NEW `signingSecret` ONCE — forward it to the user; deliveries signed with the old secret stop verifying as soon as this returns, so the receiver must be updated.

ParameterTypeDescription
id *stringWebhook id

webhooks_deliveries

List recent delivery attempts for a webhook — status code, attempt count, error, duration, timestamps. THIS IS THE VERIFY CALL: after webhooks_create, webhooks_test, or webhooks_replay, read it to confirm the webhook actually landed (and to see the receiver's response when it didn't) instead of trusting the enqueue result.

ParameterTypeDescription
id *stringWebhook id

webhooks_dead

List a webhook's dead-letter queue — deliveries that exhausted their retries, with the outbox id, payload, and last error. Diagnose the receiver first (webhooks_get for the URL/auth, webhooks_test for a live probe), then requeue rows with webhooks_requeue.

ParameterTypeDescription
id *stringWebhook id

webhooks_requeue

Requeue ONE dead-lettered delivery for another attempt, by its outbox id from webhooks_dead. Fix the receiver first — a requeue against a still-broken endpoint just dies again. Verify with webhooks_deliveries.

ParameterTypeDescription
id *stringWebhook id
outboxId *stringOutbox id of the dead delivery (from webhooks_dead)

webhooks_replay

Replay a block range for a webhook. Replays run at 10% of batch capacity — use sparingly. Pass `force` (a short idempotency suffix) to re-run a range that was already replayed.

ParameterTypeDescription
fromBlock *integer
id *stringWebhook id
toBlock *integer
forcestringIdempotency suffix to force a duplicate replay of the range

index_ft_transfers

List decoded SIP-010 fungible-token transfers from Index. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted).

ParameterTypeDescription
assetIdentifierstringFilter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token
contractIdstringFilter by contract id
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
limitnumberMax rows for this page
orderstringasc (default) reads oldest first; desc reads newest first. A cursor only resumes under the order that issued it.
recipientstringFilter by recipient principal
senderstringFilter by sender principal
toHeightnumberEnd block height (inclusive)

index_nft_transfers

List decoded SIP-009 non-fungible-token transfers from Index. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted).

ParameterTypeDescription
assetIdentifierstringFilter by asset identifier (contract::asset)
contractIdstringFilter by contract id
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
limitnumberMax rows for this page
orderstringasc (default) reads oldest first; desc reads newest first. A cursor only resumes under the order that issued it.
recipientstringFilter by recipient principal
senderstringFilter by sender principal
toHeightnumberEnd block height (inclusive)

index_events

List chain events from the Index by event type. Use this for event types without a dedicated tool (stx_*, ft_mint/burn, nft_mint/burn, print), and for trait-scoped queries: set `trait` (e.g. sip-010) to match all contracts conforming to a standard — pair with contracts_find to discover traits. For ft/nft transfers without a trait prefer index_ft_transfers / index_nft_transfers. Contract state types (nested_contract_call, var_set, map_set, map_insert, map_delete) show what a transaction did inside contracts: every inner contract-call? and every data-var and map write, from genesis on hosted m…

ParameterTypeDescription
eventType *stringRequired. Event type to list: a decoded type or a contract state type.
assetIdentifierstringFilter by asset identifier where applicable
callerstringnested_contract_call only: the calling contract or principal
contractIdstringFilter by contract id
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
functionNamestringnested_contract_call only: the called function
limitnumberMax rows for this page
mapstringmap_set / map_insert / map_delete only: the map name
orderstringasc (default) reads oldest first; desc reads newest first. A cursor only resumes under the order that issued it.
recipientstringFilter by recipient principal
senderstringFilter by sender principal
toHeightnumberEnd block height (inclusive)
traitstringMatch contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only.
txContextbooleanJoin the submitting transaction into each event (tx_sender, tx_type, tx_status, tx_contract_id, tx_function_name). For print events it's the only source of the submitting sender.
txIdstringRestrict to one transaction
varNamestringvar_set only: the data-var name

index_state_writes

List the exact contract-state writes each block committed, in node order: {block_height, ordinal, tx_index, key, value_hex}. Shows which storage key a transaction changed when its events don't. Read one block with blockHeight, or a contract's writes over a height range.

ParameterTypeDescription
blockHeightnumberRead one block (excludes fromHeight/toHeight)
contractIdstringFilter by contract id
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
limitnumberMax rows for this page
toHeightnumberEnd block height (inclusive)
txContextbooleanJoin the writing transaction onto each row

index_contract_calls

List decoded contract calls from the Index (function name, args, result). Set `trait` (e.g. sip-010) to match calls to all contracts conforming to a standard. Note: contract-call cursors are a SEPARATE keyspace from event cursors — they are not interchangeable.

ParameterTypeDescription
contractIdstringFilter by contract id
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
functionNamestringFilter by called function name
limitnumberMax rows for this page
senderstringFilter by caller principal
toHeightnumberEnd block height (inclusive)
traitstringMatch contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.

index_blocks

List decoded blocks from Index. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted).

ParameterTypeDescription
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
limitnumberMax rows for this page
toHeightnumberEnd block height (inclusive)

index_transactions

List decoded transactions from Index. Filter by type, sender, or contract. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted).

ParameterTypeDescription
contractIdstringFilter by contract id
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart block height (inclusive)
limitnumberMax rows for this page
senderstringFilter by sender principal
toHeightnumberEnd block height (inclusive)
typestringFilter by transaction type

index_print_schema

Empirical 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. Use before writing print_event subgraph handlers to learn what's on e.data. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted).

ParameterTypeDescription
contractId *stringContract id (SP….name) whose print events to profile

index_discover

Discover the Index vocabulary: every event type and its columns, allowed/equality filters, and required-non-null fields (and which types accept `trait`). Read this before building Index queries instead of guessing filters. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted).

index_runes

List the Bitcoin Runes catalog: identity, supply, mints, and mint terms. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted). Self-host needs the bitcoin compose profile. `notes` says when Runes is not configured.

ParameterTypeDescription
cursorstringOpaque cursor from a prior response's next_cursor
limitnumberMax rows for this page
searchstringName prefix, spacers and case ignored (dog matches DOG•GO•TO•THE•MOON)
sortstringnumber (etch order, default) or mints (busiest first)

index_rune

Get one Bitcoin Rune by id or name. Returns null when not found or Runes is not configured. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted). Self-host needs the bitcoin compose profile.

ParameterTypeDescription
rune *stringRune id (840000:3) or name, any case, with or without spacers

index_rune_balances

List current Bitcoin Runes balances per unspent output. Pass exactly one of address or outpoint. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted). Self-host needs the bitcoin compose profile. `notes` says when Runes is not configured.

ParameterTypeDescription
addressstringBitcoin address. Exclusive with outpoint.
cursorstringOpaque cursor from a prior response's next_cursor
limitnumberMax rows for this page
outpointstringOutput as txid:vout. Exclusive with address.
runestringNarrow to one rune (id or name)

index_rune_activity

List Bitcoin Runes etch, mint, transfer, and burn events. Heights are Bitcoin block heights. Keyless on OSS loopback; otherwise needs INSTANCE_TOKEN (OSS) or SECONDLAYER_API_KEY (hosted). Self-host needs the bitcoin compose profile. `notes` says when Runes is not configured.

ParameterTypeDescription
addressstringFilter by Bitcoin address (transfers only carry one)
cursorstringOpaque cursor from a prior response's next_cursor
fromHeightnumberStart Bitcoin block height (inclusive)
kindarrayEvent kinds to include
limitnumberMax rows for this page
runestringFilter by rune (id or name)
toHeightnumberEnd Bitcoin block height (inclusive)
txidstringRestrict to one Bitcoin txid

batch_query

Run up to 10 public /v1 reads in one round trip (POST /v1/batch). Each item keeps its own auth/quota/pay-per-call semantics; results return in order with per-item status. Paths must start with /v1/index, /v1/subgraphs, /v1/streams, or /v1/contracts.

ParameterTypeDescription
requests *arrayRead descriptors, executed concurrently

streams_tip

Current 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. Call it before a cursor walk to know where the stream ends, and after an ingest to check lag.

streams_dumps

List the Streams bulk parquet dumps manifest — coverage range, latest_finalized_cursor, and per-file metadata (block range, row count, size, sha256, signed URL). This is the cold backfill path for downloading all raw data; fetch the file URLs directly (e.g. with DuckDB). Requires the dumps base URL to be configured (SL_STREAMS_DUMPS_URL). For live reads use REST GET /v1/streams/events; for tip/lag use streams_tip.

contracts_find

Discover deployed Stacks contracts conforming to a trait (e.g. "sip-010", "sip-009", "sip-013"). The discovery endpoint for "which contracts implement X". Reads are public.

ParameterTypeDescription
trait *stringRequired. Trait to match (e.g. "sip-010").
conformancestringdeclared = parsed from source, inferred = ABI shape-match, any = either (default)
cursorstringOpaque cursor from a prior response's next_cursor
includestringSet to "abi" to include each contract's full ABI
limitnumberPage size, 1–500 (default 100)

contracts_get_abi

Fetch a single deployed contract's ABI from the registry (prod-safe). Returns the contract's metadata + full ABI (functions, maps, variables, fungible/non-fungible tokens). Returns not_found if the contract isn't in the registry. Use it to inspect a contract before subgraphs_scaffold.

ParameterTypeDescription
contractId *stringFully qualified contract id (e.g. SP….amm-pool-v2-01)

codegen_index_schema

Generate an ORM schema for the Index tables (blocks, transactions, decoded_events, …) — the same output as `sl codegen index`. Returns the file contents as text; write it wherever your project keeps its schema. Use `tables` to emit only what you read.

ParameterTypeDescription
datasourceEnvstringPrisma only: datasource url env var (default DATABASE_URL)
schemaNamestringPostgres schema to qualify table names with
tablesarrayRestrict to these Index tables (default: all)
targetstringOutput flavor (default kysely)

instance_status

Decoder health and empty-index diagnosis from GET /public/status. If state is empty-index, next tool is archive_bootstrap. Poll until index.decoders are ok before treating Index as ready — do not start decoders. Then archive_verify, then codegen_index_schema. Do not download parquet.

archive_verify

Read-only, free compare of this instance against a signed archive (POST /v1/archive/verify). unanchored means pin a key or check the URL — not that the instance is fine. After bootstrap, poll instance_status until decoders ok, then this, then codegen_index_schema. Do not download parquet.

ParameterTypeDescription
against *stringArchive manifest URL
fromBlockintegerFirst height (inclusive)
targetstringVerify target (default raw)
toBlockintegerLast height (inclusive)

archive_latest

Signed pointer to the official archive tree (hosted). Needs SECONDLAYER_API_KEY (sk-sl_*), not INSTANCE_TOKEN. Use the returned origin as --against for archive_bootstrap. Do not download parquet.

ParameterTypeDescription
againststringOverride latest.json URL (default official tree)

archive_quote

Price a hosted archive fetch (metered). Needs SECONDLAYER_API_KEY (sk-sl_*), not INSTANCE_TOKEN. Quote happens here; bootstrap/repair also quote inside the CLI. Do not download parquet.

ParameterTypeDescription
flow *stringbootstrap or repair
paths *arrayPartition paths to price

credits_balance

Archive credits balance at api.secondlayer.tools. Needs SECONDLAYER_API_KEY (sk-sl_*); INSTANCE_TOKEN is the instance.

archive_bootstrap

Restore verified history into this instance (secondlayer bootstrap --against … --yes --json). Metered against the official archive; quote happens inside the CLI. After bootstrap, poll instance_status until decoders ok, then archive_verify, then codegen_index_schema. Do not download parquet.

ParameterTypeDescription
against *stringArchive manifest URL
fromBlockintegerRestore from this height instead of genesis
toBlockintegerStop at this height instead of the archive tip

archive_repair

Plan (default) or apply a repair of local chain data against a signed archive. Metered when apply fetches from the official archive. After apply, poll instance_status until decoders ok, then archive_verify. Do not download parquet.

ParameterTypeDescription
against *stringArchive manifest URL
applybooleanWrite the repair (default plan-only)
fromBlockintegerFirst height to consider
toBlockintegerLast height to consider