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:
| Scenario | Recommended Method |
|---|---|
| Monitor your own 1--20 neurons | getSelectiveMetagraph (this method) |
| Build a full subnet explorer | getMetagraph |
| Alert on specific neuron performance | This method (poll every tempo) |
| Analyze entire weight matrix | getMetagraph |
| Mobile app with bandwidth limits | This method |
| Cross-subnet neuron tracking | This 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
| Position | Name | Type | Required | Description |
|---|---|---|---|---|
| 0 | netuid | u16 | Yes | The subnet identifier |
| 1 | uids | Vec<u16> | Yes | Array of neuron UIDs to include in the response |
| 2 | at | BlockHash | No | Optional 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:
| Field | Type | Description |
|---|---|---|
netuid | u16 | The subnet identifier |
n | u16 | Number of neurons in the filtered result |
block | u64 | Block number at capture time |
hotkeys | Vec<AccountId32> | Hotkey addresses for the requested neurons |
coldkeys | Vec<AccountId32> | Coldkey addresses for the requested neurons |
uids | Vec<u16> | The filtered neuron UIDs |
stake | Vec<u64> | Total stake per neuron (RAO). Divide by 1e9 for TAO |
trust | Vec<u16> | Trust scores (0--65535 scaled) |
consensus | Vec<u16> | Consensus scores (0--65535 scaled) |
incentive | Vec<u16> | Incentive scores (0--65535 scaled) |
dividends | Vec<u16> | Dividend scores (0--65535 scaled) |
emission | Vec<u64> | Emissions per neuron per tempo (RAO) |
validator_permit | Vec<bool> | Validator permit flags |
active | Vec<bool> | Active neuron flags |
last_update | Vec<u64> | Last block each neuron set weights |
rank | Vec<u16> | Rank scores (0--65535 scaled) |
weights | Vec<Vec<(u16, u16)>> | Weight matrix entries for selected neurons |
bonds | Vec<Vec<(u16, u16)>> | Bond matrix entries for selected neurons |
axons | Vec<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
weightsandbondssparse 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 AxonInfocontainsip(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
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
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
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
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 Scenario | Behavior | Recommended Action |
|---|---|---|
| Invalid netuid | Returns null | Verify subnet exists via subnetInfo_getSubnetsInfo |
| Empty UIDs array | May return error or empty result | Always provide at least one UID |
| UID out of range | Neuron data may be omitted or zeroed | Get n from getMetagraph or getSubnetsInfo to know valid UID range |
| Too many UIDs | No hard limit, but approaches full metagraph cost | For large sets (50+), fetch the full metagraph instead |
| Invalid block hash | Returns JSON-RPC error | Verify block hash exists |
| Node not synced | May return stale data | Check 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.
Related Methods
subnetInfo_getMetagraph— Get the full metagraph for a subnetsubnetInfo_getAllMetagraphs— Get metagraphs for all subnetssubnetInfo_getSelectiveMechagraph— Get filtered mechagraph data for specific neuron UIDssubnetInfo_getMechagraph— Get the full mechagraph for a subnet mechanismneuronInfo_getNeuron— Get detailed info for a single neuron by UID
subnetInfo_getSelectiveMechagraph - Bittensor RPC Method
Retrieve SCALE-encoded mechagraph data filtered by specific neuron UIDs for a Bittensor subnet. Enables targeted mechanism queries without fetching the full mechagraph.
subnetInfo_getSubnetHyperparams - JSON-RPC...
Fetch SCALE-encoded hyperparameters for a given Bittensor subnet.