Docs

subnetInfo_getSelectiveMetagraph - Bittensor RPC Method

Retrieve SCALE-encoded metagraph data filtered by specific neuron UIDs for a Bittensor subnet. Enables efficient targeted queries without fetching the full metagraph.

Overview

The subnetInfo_getSelectiveMetagraph method returns SCALE-encoded metagraph data filtered to include only the specified neuron UIDs. This is the targeted version of subnetInfo_getMetagraph -- instead of returning the complete metagraph for all neurons in a subnet, it returns data only for the neurons you specify.

This method is ideal for monitoring applications that track a specific set of validators or miners. For large subnets with thousands of neurons, fetching the full metagraph on every poll is expensive in both bandwidth and processing time. The selective metagraph lets you efficiently query just the neurons you care about.

Selective vs. Full Metagraph

Choose the right method based on your needs:

ScenarioRecommended Method
Monitor your own 1--20 neuronsgetSelectiveMetagraph (this method)
Build a full subnet explorergetMetagraph
Alert on specific neuron performanceThis method (poll every tempo)
Analyze entire weight matrixgetMetagraph
Mobile app with bandwidth limitsThis method
Cross-subnet neuron trackingThis method, called per subnet

Bandwidth savings example: A subnet with 256 neurons might return a 500 KB metagraph. Querying 5 specific neurons returns roughly 10--20 KB -- a 25--50x reduction.

Parameters

PositionNameTypeRequiredDescription
0netuidu16YesThe subnet identifier
1uidsVec<u16>YesArray of neuron UIDs to include in the response
2atBlockHashNoOptional block hash to query at a specific block. Pass null for the latest state

Response

The result is a JSON array of SCALE bytes. When decoded, it contains the same fields as a full metagraph but only for the requested UIDs:

FieldTypeDescription
netuidu16The subnet identifier
nu16Number of neurons in the filtered result
blocku64Block number at capture time
hotkeysVec<AccountId32>Hotkey addresses for the requested neurons
coldkeysVec<AccountId32>Coldkey addresses for the requested neurons
uidsVec<u16>The filtered neuron UIDs
stakeVec<u64>Total stake per neuron (RAO). Divide by 1e9 for TAO
trustVec<u16>Trust scores (0--65535 scaled)
consensusVec<u16>Consensus scores (0--65535 scaled)
incentiveVec<u16>Incentive scores (0--65535 scaled)
dividendsVec<u16>Dividend scores (0--65535 scaled)
emissionVec<u64>Emissions per neuron per tempo (RAO)
validator_permitVec<bool>Validator permit flags
activeVec<bool>Active neuron flags
last_updateVec<u64>Last block each neuron set weights
rankVec<u16>Rank scores (0--65535 scaled)
weightsVec<Vec<(u16, u16)>>Weight matrix entries for selected neurons
bondsVec<Vec<(u16, u16)>>Bond matrix entries for selected neurons
axonsVec<AxonInfo>Network endpoint info for selected neurons

SCALE Decoding

The response decodes to a filtered MetagraphInfo struct. Vector fields are ordered by the position of UIDs in your request (not by UID value).

Using @polkadot/api: Register Bittensor types including MetagraphInfo and AxonInfo. The decoded result has identical field types to the full metagraph.

Using bittensor Python SDK: Some SDK versions support selective metagraph queries directly. For manual decoding, parse the hex as a MetagraphInfo struct using the Bittensor type registry.

Key decoding notes:

  • Response vectors are positionally indexed: element 0 corresponds to the first UID you requested, element 1 to the second, and so on
  • The weights and bonds sparse vectors for each neuron still reference global UIDs from the full subnet, not re-indexed positions
  • If a requested UID is not registered (empty slot), it may be omitted or have is_null: true
  • AxonInfo contains ip (u128), port (u16), version (u32), ip_type (u8), protocol (u8). IPv4 addresses fit in 4 bytes of the u128
  • Score fields are u16 (0--65535). Divide by 65535 for normalized float values (0.0--1.0)

Code Examples

Using SubstrateExamples

Query with Python

Python
import requests
import json

url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'

# Fetch metagraph data for neurons 0 and 1 in subnet 1
payload = {
    'jsonrpc': '2.0',
    'method': 'subnetInfo_getSelectiveMetagraph',
    'params': [1, [0, 1], None],
    'id': 1
}

response = requests.post(url, json=payload)
result = response.json()

if result.get('result'):
    scale_bytes = result['result']
    print(f'Selective metagraph data size: {len(scale_bytes)} bytes')
else:
    print('No data returned for specified neurons')

# Monitor a watch list of neurons:
# my_neurons = [3, 17, 42, 88, 155]
# payload['params'] = [1, my_neurons, None]
# response = requests.post(url, json=payload)

Full Python monitoring dashboard

Python
import requests
import json
import time

url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'

# Define neurons to monitor across subnets
watchlist = {
    1: [0, 3, 15, 42],      # Subnet 1: specific UIDs
    18: [0, 1, 7, 22],      # Subnet 18: specific UIDs
}

def fetch_selective(netuid, uids):
    payload = {
        'jsonrpc': '2.0',
        'method': 'subnetInfo_getSelectiveMetagraph',
        'params': [netuid, uids, None],
        'id': 1
    }
    resp = requests.post(url, json=payload, timeout=15)
    return resp.json()

# Periodic monitoring loop
for netuid, uids in watchlist.items():
    result = fetch_selective(netuid, uids)
    if result.get('result'):
        data_size = len(result['result']) // 2
        print(f"Subnet {netuid}: fetched {data_size:,} bytes for {len(uids)} neurons")
    else:
        print(f"Subnet {netuid}: no data")

# With bittensor SDK for decoded data:
# import bittensor as bt
# sub = bt.subtensor(network='finney')
#
# for netuid, uids in watchlist.items():
#     meta = sub.metagraph(netuid=netuid)
#     for uid in uids:
#         if uid < meta.n:
#             print(f"Subnet {netuid} UID {uid}: "
#                   f"incentive={meta.I[uid]:.4f}, "
#                   f"emission={meta.E[uid]:.6f} TAO, "
#                   f"active={meta.active[uid]}, "
#                   f"last_update=block {meta.last_update[uid]}")

Query with JavaScript

JavaScript
import { ApiPromise, WsProvider } from '@polkadot/api';

const provider = new WsProvider('wss://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });

// Fetch selective metagraph for UIDs 0 and 1 on subnet 1
const result = await api.rpc.subnetInfo.getSelectiveMetagraph(1, [0, 1]);
console.log('Selective data size:', result.toHex().length, 'bytes');

// Monitor a larger watchlist
const watchlist = [0, 3, 7, 15, 42, 88, 155];
const selective = await api.rpc.subnetInfo.getSelectiveMetagraph(1, watchlist);
console.log(`Data for ${watchlist.length} neurons:`, selective.toHex().length, 'bytes');

await api.disconnect();

Query with cURL

Bash
curl -X POST https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "subnetInfo_getSelectiveMetagraph",
    "params": [1, [0, 1, 5, 10], null],
    "id": 1
  }'

Error Handling

Error ScenarioBehaviorRecommended Action
Invalid netuidReturns nullVerify subnet exists via subnetInfo_getSubnetsInfo
Empty UIDs arrayMay return error or empty resultAlways provide at least one UID
UID out of rangeNeuron data may be omitted or zeroedGet n from getMetagraph or getSubnetsInfo to know valid UID range
Too many UIDsNo hard limit, but approaches full metagraph costFor large sets (50+), fetch the full metagraph instead
Invalid block hashReturns JSON-RPC errorVerify block hash exists
Node not syncedMay return stale dataCheck system_health

Common Use Cases

  • Targeted monitoring — Track specific validators or miners within a subnet without the overhead of the full metagraph.
  • Personal dashboards — Build monitoring views focused on a user's own registered neurons across subnets.
  • Bandwidth optimization — Significantly reduce response sizes for large subnets when polling frequently.
  • Alerting systems — Efficiently poll specific neurons' trust, incentive, and emission scores at regular intervals.
  • Competitive intelligence — Monitor specific competitors' performance metrics without downloading all subnet data.
  • Mobile apps — Keep payload sizes small for mobile-friendly subnet monitoring applications.
  • Multi-subnet tracking — Monitor the same operator's neurons across multiple subnets by making one call per subnet.