metashrew_* Methods

The metashrew_* namespace provides access to the Metashrew indexer, which powers custom WASM-based blockchain views.

Overview

Metashrew is a flexible indexer that runs WebAssembly programs against Bitcoin blockchain data. It enables:

  • Custom indexing logic
  • Efficient state queries
  • Protocol-specific views (Alkanes, Protorunes, etc.)

Methods

metashrew_height

Get the current indexed height of Metashrew.

Request:

{
  "jsonrpc": "2.0",
  "method": "metashrew_height",
  "params": [],
  "id": 1
}

Response:

{
  "jsonrpc": "2.0",
  "result": "925736",
  "id": 1
}

Lua Example:

local height = tonumber(_RPC.metashrew_height())
return { indexed_height = height }
metashrew_height
Returns the current block height indexed by Metashrew.
Click "Run" to execute the request...

metashrew_view

Execute a view function on the Metashrew indexer.

Parameters:

  • 0 (string): View method name
  • 1 (any): Input data (method-specific)
  • 2 (string): Block tag ("latest" or block number)

Request:

{
  "jsonrpc": "2.0",
  "method": "metashrew_view",
  "params": [
    "protorunesbyaddress",
    {
      "address": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
      "protocolTag": "1"
    },
    "latest"
  ],
  "id": 1
}

Response:

{
  "jsonrpc": "2.0",
  "result": {
    "outpoints": [
      {
        "outpoint": {
          "txid": "abc123...",
          "vout": 0
        },
        "runes": [
          {
            "id": { "block": 840000, "tx": 1 },
            "amount": "1000000"
          }
        ]
      }
    ]
  },
  "id": 1
}

Lua Example:

local address = args[1]
local result = _RPC.metashrew_view(
  "protorunesbyaddress",
  {
    address = address,
    protocolTag = "1"
  },
  "latest"
)
return { result_type = type(result) }

Common View Methods

The following view methods are commonly available through metashrew_view:

protorunesbyaddress

Get protorunes (including alkanes) held by an address.

Input:

{
  "address": "bc1q...",
  "protocolTag": "1"
}

Lua Example:

local result = _RPC.metashrew_view(
  "protorunesbyaddress",
  { address = args[1], protocolTag = "1" },
  "latest"
)
return { result_type = type(result) }

protorunesbyoutpoint

Get protorunes at a specific outpoint.

Input:

{
  "txid": "abc123...",
  "vout": 0,
  "protocolTag": "1"
}

runebyid

Get rune information by ID.

Input:

{
  "block": 840000,
  "tx": 1
}

Block Tags

The block_tag parameter controls which state to query:

  • "latest" - Most recent indexed block
  • "850000" - Specific block height (as string)

Protocol Tags

For protorune-based queries, the protocolTag identifies the protocol:

  • "1" - Alkanes
  • "13" - Other protorunes

Sync Status Check

Compare indexer heights to check sync status:

Lua Example:

local metashrew_h = tonumber(_RPC.metashrew_height())
local btc_h = _RPC.btc_getblockcount()

return {
  metashrew = metashrew_h,
  bitcoin = btc_h,
  synced = metashrew_h >= btc_h - 2,
  blocks_behind = btc_h - metashrew_h
}