Get Started
Decoded Stacks chain data from block 1, reorg-safe, and every row checkable.
Copy this prompt into your agent. Hosted reads need a key.
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 docs key: `curl -X POST https://api.secondlayer.tools/api/public/docs-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`Then ask your agent to build something:
Prompt
Before writing code, ask me what I want to track. If I'm not sure, suggest three starting points that fit this project, such as one token's transfers or every call to one contract. Then build the smallest working Index consumer, with rows and the cursor committed together, and show me the first rows.I need my contract as a tableOne TypeScript file becomes a table and a REST API.I need a POST when it happensA signed POST to your URL on a chain event.I need decoded chain dataEvery Stacks event, decoded, from block 1.I need to know what a contract changedWho changed what in any contract, and when.I need the raw eventsWhat the node emitted, in order, signed.I need history I can checkSigned history to verify, repair and bootstrap.
Cursors and PagesOne envelope, one loop for every list.CheckpointsRows and cursor commit together.ReorgsThe one line that handles a reorg.VerifyCheck any row on your machine.
Self-hostThe stack on Docker Compose.Deploy a ConsumerDocker, EC2 or systemd.SinksRows and rollbacks to Postgres.Local ChainA devnet on your laptop.
Agent SkillRules agents get wrong.MCPLive state for agents.Docs as MarkdownAny docs page as Markdown.
Edit on GitHub