# PRC20 APIs

Base URL: `https://indexer.blackpearlmarket.com`

Most PRC20 endpoints return:

```json
{ "message": "Success", "prev": null, "next": null, "result": [] }
```

Common query parameters: `limit`, `next`, `prev`, `tick`, and `op` where supported. Clients should follow response `next` and `prev` values instead of constructing cursors manually.

## Health

### `GET /health`

Returns public service health and indexing status.

Example response shape:

```json
{
  "status": "ok",
  "indexing_status": "synced",
  "height": 57157,
  "indexed_height": 57156,
  "lag": 1
}
```

## Tokens

### `GET /api/v1/prc20/tokenlist`

Lists indexed PRC20 tokens.

Lists indexed PRC20 tokens.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": "25",
  "result": [
    {
      "tick": "PRL",
      "dec": "8",
      "max": "2100000000000000",
      "lim": "100000000",
      "minted": "100000000",
      "pre": "0",
      "cid": null,
      "holders": 128
    }
  ]
}
```

### `GET /api/v1/prc20/stats`

Returns aggregate PRC20 stats such as indexed height, token counts, holder counts, listing counts, and marketplace totals.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": null,
  "result": [
    {
      "last_processed_height": 57156,
      "blocks_indexed": 57156,
      "events_total": 1234,
      "events_valid": 1200,
      "tokens_deployed": 12,
      "distinct_holders": 345,
      "lists_open": 9,
      "lists_filled": 20,
      "lists_cancelled": 3,
      "lists_invalid_spent": 0,
      "total_protocol_fee_paid_sat": "100000",
      "total_protocol_fee_paid_pearl": "0.00100000",
      "total_seller_paid_sat": "9900000",
      "total_seller_paid_pearl": "0.09900000"
    }
  ]
}
```

### `GET /api/v1/prc20/token/{tick}`

Returns deployment details for one ticker.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": null,
  "result": [
    {
      "tick": "PRL",
      "dec": "8",
      "max": "2100000000000000",
      "lim": "100000000",
      "minted": "100000000",
      "pre": "0",
      "cid": null,
      "deployer": "prl1...",
      "deploy_txid": "abc...",
      "deploy_height": 100
    }
  ]
}
```

## Balances

### `GET /api/v1/prc20/address/{address}/tokenlist`

Returns PRC20 balances for an address.

Returns token balances for one Pearl address. `balance` is raw integer units and `balance_normalized` is formatted for UI display.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": null,
  "result": [
    {
      "tick": "PRL",
      "dec": "8",
      "balance": "100000000",
      "balance_normalized": "1.00000000"
    }
  ]
}
```

### `GET /api/v1/prc20/address/{address}/token/{tick}`

Returns one ticker balance for one address.

## Market

### `GET /api/v1/prc20/market/{tick}`

Returns active market entries for a ticker.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": null,
  "result": [
    {
      "id": "list:abc:0",
      "tick": "PRL",
      "amount": "100000000",
      "owner": "prl1...",
      "seller_address": "prl1...",
      "pay": "PEARL",
      "price": "125000000",
      "protocol_fee_bps": 300,
      "protocol_fee_amount": "3750000",
      "seller_net_amount": "121250000",
      "exp": null,
      "created_txid": "abc...",
      "created_height": 123,
      "fill_txid": null,
      "anchor_txid": "def...",
      "anchor_vout": 0,
      "close_kind": null,
      "lifecycle_state": "open",
      "action_required": null
    }
  ]
}
```

### `GET /api/v1/prc20/market/{tick}/seller/{address}`

Returns seller-specific listings for a ticker and Pearl address.

### `GET /api/v1/prc20/market/{tick}/history`

Returns marketplace history, including open, filled, cancelled, invalid-spent, and expired/open lifecycle data where indexed.

### `GET /api/v1/prc20/market/{tick}/summary`

Returns market summary for a ticker.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": null,
  "result": [
    {
      "tick": "PRL",
      "open_count": 9,
      "filled_count": 20,
      "cancelled_count": 3,
      "invalid_spent_count": 0,
      "expired_open_count": 0,
      "total_filled_amount": "2000000000",
      "total_invalid_spent_refunded_amount": "0",
      "total_protocol_fee_paid_sat": "100000",
      "total_protocol_fee_paid_pearl": "0.00100000",
      "total_seller_paid_sat": "9900000",
      "total_seller_paid_pearl": "0.09900000",
      "floor_price_sat": "125000000",
      "floor_price_pearl": "1.25000000",
      "floor_change_24h_pct": "0.0000"
    }
  ]
}
```

### `GET /api/v1/prc20/market/quote/{id}`

Returns a quote for a market item, including price, seller net, protocol fee, anchor data, expected outputs, and payload template.

Example:

```json
{
  "message": "Success",
  "prev": null,
  "next": null,
  "result": [
    {
      "intent_id": "list:abc:0",
      "tick": "PRL",
      "amount": "100000000",
      "pay": "PEARL",
      "price_sat": "125000000",
      "protocol_fee_bps": 300,
      "protocol_fee_sat": "3750000",
      "seller_net_sat": "121250000",
      "seller_address": "prl1...",
      "protocol_address": "prl1...",
      "anchor_txid": "def...",
      "anchor_vout": 0,
      "policy_hash": "0x...",
      "seller_anchor_sig_hex": "0x...",
      "outputs": [
        { "address": "prl1...", "amount_sat": "121250000" },
        { "address": "prl1...", "amount_sat": "3750000" }
      ],
      "payload_template": {
        "p": "prc20",
        "op": "send",
        "id": "list:abc:0",
        "to": "__BUYER_ADDRESS__"
      }
    }
  ]
}
```

### `GET /api/v1/prc20/market/fill-template/{id}/{to}`

Returns a fill transaction template for a listing and recipient address.

## Operations

### `GET /api/v1/prc20/oplist`

Returns PRC20 operation list.

Supports common pagination query params and optional `tick` / `op` filters.

### `GET /api/v1/prc20/address/{address}/history`

Returns address operation history.

Rows include height, txid, operation, ticker, direction, amount, and addresses.

Example operation row:

```json
{
  "block_height": 123,
  "txid": "abc...",
  "vout": 0,
  "op": "mint",
  "tick": "PRL",
  "valid": 1,
  "reason": null,
  "payload_json": "{\"p\":\"prc20\",\"op\":\"mint\"}"
}
```

## Errors

Database errors are returned through the API wrapper with an error message. Route-specific not-found behavior can be an empty `result` array rather than an HTTP 404.

**To verify before production release:** confirm exact HTTP status codes for every PRC20 route against integration tests before publishing a strict client contract.

### `GET /api/v1/prc20/op/{txid}`

Returns operation details for a transaction.

Returns matching operation rows for the transaction id.

### `GET /api/v1/prc20/op/{txid}/{vout}`

Returns operation details for a transaction output.

Returns a single operation row when found.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blackpearlmarket.com/overview-2/prc20.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
