<!-- source: https://www.secondlayer.tools/docs/contract-calls -->

# Contract Calls

Every call to a contract function, with its arguments already parsed from Clarity, from block 1.

```bash
curl "$SECONDLAYER_API_URL/v1/index/contract-calls?contract_id=SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token&function_name=transfer&from_height=9340000&limit=1" \
  -H "Authorization: Bearer sk-sl_…"
```

```ts
import { Index } from "@secondlayer/sdk";

const index = new Index();

const page = await index.contractCalls.list({
  contractId: "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
  functionName: "transfer",
  fromHeight: 9340000,
  limit: 1,
});
```

```json response.json status=200
{
  "contract_calls": [
    {
      "cursor": "9341326:0",
      "block_height": 9341326,
      "block_time": "2026-10-28T00:52:36.000Z",
      "tx_id": "0x385726bb0fe44cac3c127096a28ddd3c5aba20e45e7bb7d09cbba15b9b579d9e",
      "tx_index": 0,
      "contract_id": "SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token",
      "function_name": "transfer",
      "sender": "SP2X2S5J0DXXRBR786CVVT15SWZT9T6E5D5YYXXF1",
      "status": "success",
      "args": ["10514538", "SP2X2S5J0DXXRBR786CVVT15SWZT9T6E5D5YYXXF1", "SP1SYS7ZHE8Z05WGJYF7EHXCYCXSJY0FW75MT7M9Z", null],
      "result": { "ok": true },
      "result_hex": "0x0703"
    }
  ],
  "next_cursor": "9341326:0",
  "tip": { "block_height": 9348931, "finalized_height": 9348069, "lag_seconds": 18 },
  "reorgs": []
}
```

`args` holds the arguments in order, one entry per parameter, as plain JSON. Read the names from the contract's ABI: `transfer` takes the amount, sender, recipient, then an optional memo.

## Narrow It

| Narrow by | Param |
| --- | --- |
| One function | `functionName` |
| Who called it | `sender` |
| Several contracts | `contractId` as a list (max 20) |
| Every contract of a standard | `trait`, instead of `contractId` |
| A block range | `fromHeight`, `toHeight` |

- There is no `status` filter: failed calls come back too, so check each row's `status`.
- Only calls a transaction makes directly are listed. Calls between contracts are on [Contract State](https://www.secondlayer.tools/docs/contract-state.md).
- Reads run oldest first; there is no `order` parameter on this feed.

## Tradeoff

A read with no `fromHeight` or cursor covers only the last 17,280 blocks, and a busy function means many rows, so narrow by height before you page ([Cursors and Pages](https://www.secondlayer.tools/docs/cursors.md)). Every filter and the response schema: [Decoded contract-call transactions](https://www.secondlayer.tools/docs/api-reference.md#list-contract-calls).

## Read next

- [Contract State](https://www.secondlayer.tools/docs/contract-state.md)
- [Cursors and Pages](https://www.secondlayer.tools/docs/cursors.md)
- [API](https://www.secondlayer.tools/docs/api-reference.md)

## Notes for agents

- Route: GET /v1/index/contract-calls, top-level calls only (SDK: sl.index.contractCalls.list / .walk / .consume). contract_id (comma list, max 20) or trait, not both. No status filter, no order parameter.
- cursor and from_height are mutually exclusive. null next_cursor means an empty page.
- args: uint is a decimal string, optional none is null; names come from the ABI, not the row.
- walk() keeps no checkpoint and ignores reorgs: use consume() to keep rows.

## Setup

Ensure setup once, skipping any step already done:
- CLI: `bun add -g @secondlayer/cli`
- Instance: `secondlayer init` writes `INSTANCE_TOKEN`. Loopback `/v1` reads need no key.
- Hosted reads: export `SECONDLAYER_API_KEY` (`sk-sl_*`) or buy credits with `secondlayer credits buy` (`balance`, `refill`), then `secondlayer whoami`
