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.
Overview
The subnetInfo_getSelectiveMechagraph method returns SCALE-encoded mechagraph data filtered to include only the specified neuron UIDs. This is the targeted version of subnetInfo_getMechagraph -- instead of returning the complete mechagraph for all neurons in a mechanism, it returns data only for the neurons you are interested in.
This method is useful when monitoring a specific set of miners or validators within a mechanism and you want to avoid downloading and parsing the full mechagraph payload. For subnets with hundreds or thousands of neurons, selective queries can significantly reduce bandwidth and processing time.
Selective vs. Full Mechagraph
Choose the right method based on your use case:
| Scenario | Recommended Method |
|---|---|
| Monitor 1--50 specific neurons | getSelectiveMechagraph (this method) |
| Analyze full mechanism topology | getMechagraph |
| Compare mechanisms for specific neurons | This method, called once per mecid |
| Build complete mechanism heatmaps | getMechagraph |
| Real-time alerting on key neurons | This method (lower bandwidth per poll) |
Parameters
| Position | Name | Type | Required | Description |
|---|---|---|---|---|
| 0 | netuid | u16 | Yes | The subnet identifier |
| 1 | mecid | u16 | Yes | The mechanism identifier within the subnet |
| 2 | uids | Vec<u16> | Yes | Array of neuron UIDs to include in the response |
| 3 | 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 mechagraph but only for the requested UIDs:
| Field | Type | Description |
|---|---|---|
netuid | u16 | The subnet identifier |
mecid | u16 | The mechanism identifier |
n | u16 | Number of neurons in the filtered result |
hotkeys | Vec<AccountId32> | Hotkey addresses for the requested neurons |
uids | Vec<u16> | The filtered neuron UIDs |
stake | Vec<u64> | Stake per neuron (RAO). Divide by 1e9 for TAO |
trust | Vec<u16> | Mechanism-specific trust scores (0--65535 scaled) |
incentive | Vec<u16> | Mechanism-specific incentive scores (0--65535 scaled) |
dividends | Vec<u16> | Mechanism-specific dividend scores (0--65535 scaled) |
emission | Vec<u64> | Mechanism-specific emissions (RAO per tempo) |
weights | Vec<Vec<(u16, u16)>> | Weight matrix entries for selected neurons |
bonds | Vec<Vec<(u16, u16)>> | Bond matrix entries for selected neurons |
SCALE Decoding
The response decodes to a filtered MechagraphInfo struct. The structure is the same as the full mechagraph but all vector fields only contain entries for the requested UIDs, in the order they were requested.
Using @polkadot/api: Register Bittensor types including MechagraphInfo. The decoded result has identical field types to the full mechagraph response.
Using bittensor Python SDK: Some SDK versions support sub.get_selective_mechagraph(netuid, mecid, uids). For manual decoding, use scalecodec with the Bittensor type registry.
Key decoding notes:
- The response vectors are indexed by position, not by UID. The first element corresponds to the first UID in your request, and so on
- If a requested UID does not exist in the mechanism, it may be omitted from the response or returned with zero values (depending on runtime version)
- The
weightsandbondsmatrices for selected neurons still reference UIDs from the full subnet -- they are not re-indexed - Score fields are u16 scaled to 0--65535; divide by 65535 for float values
Code Examples
Using SubstrateExamples
Query with Python
import requests
import json
url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'
# Fetch mechagraph data for neurons 0 and 1 in subnet 1, mechanism 0
payload = {
'jsonrpc': '2.0',
'method': 'subnetInfo_getSelectiveMechagraph',
'params': [1, 0, [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 mechagraph data size: {len(scale_bytes)} bytes')
else:
print('No data returned for specified neurons')
# Query a larger set of UIDs for batch monitoring:
# uids_to_watch = [0, 5, 12, 42, 100]
# payload['params'] = [1, 0, uids_to_watch, None]
# response = requests.post(url, json=payload)Full Python monitoring example
import requests
import json
import time
url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'
# Monitor specific neurons across mechanisms
netuid = 1
watched_uids = [0, 3, 7, 15, 42]
def fetch_selective_mechagraph(netuid, mecid, uids):
payload = {
'jsonrpc': '2.0',
'method': 'subnetInfo_getSelectiveMechagraph',
'params': [netuid, mecid, uids, None],
'id': 1
}
response = requests.post(url, json=payload)
return response.json()
# Compare performance across mechanisms for watched neurons
for mecid in range(2):
result = fetch_selective_mechagraph(netuid, mecid, watched_uids)
if result.get('result'):
data = result['result']
print(f"Mechanism {mecid}: {len(data) // 2:,} bytes for {len(watched_uids)} neurons")
else:
print(f"Mechanism {mecid}: not available")
# With bittensor SDK for decoded analysis:
# import bittensor as bt
# sub = bt.subtensor(network='finney')
#
# # Poll mechanism scores for watched neurons
# for mecid in [0, 1]:
# mech = sub.get_selective_mechagraph(netuid=1, mecid=mecid, uids=watched_uids)
# if mech:
# for i, uid in enumerate(watched_uids):
# print(f" UID {uid}: incentive={mech.I[i]:.4f}, trust={mech.T[i]:.4f}")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 mechagraph for UIDs 0 and 1
const result = await api.rpc.subnetInfo.getSelectiveMechagraph(1, 0, [0, 1]);
console.log('Selective data size:', result.toHex().length, 'bytes');
// Monitor a watchlist
const watchlist = [0, 5, 12, 42, 100];
const selective = await api.rpc.subnetInfo.getSelectiveMechagraph(1, 0, 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_getSelectiveMechagraph",
"params": [1, 0, [0, 1, 5, 10], null],
"id": 1
}'Error Handling
| Error Scenario | Behavior | Recommended Action |
|---|---|---|
| Invalid netuid | Returns null | Verify subnet exists via subnetInfo_getSubnetsInfo |
| Invalid mecid | Returns null or empty | Most subnets only have mecid 0 |
| 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 | Verify UIDs exist in the subnet first |
| Too many UIDs | No hard limit, but large requests approach full mechagraph cost | For 50+ UIDs, consider fetching the full mechagraph instead |
| Invalid block hash | Returns JSON-RPC error | Verify block hash exists |
Common Use Cases
- Targeted monitoring — Track specific miners or validators within a mechanism without downloading the entire mechagraph.
- Performance dashboards — Build monitoring views that focus on a user's own neurons or a watched set of neurons.
- Bandwidth optimization — Reduce payload size when you only need data for a small subset of the subnet's neurons.
- Alerting systems — Poll specific neurons' incentive and trust scores at regular intervals with minimal overhead.
- Competitive analysis — Monitor specific competitors' mechanism-level performance without full data retrieval.
- Cross-mechanism comparison — Compare how the same neurons score across different mechanisms by calling this method once per mecid.
Related Methods
subnetInfo_getMechagraph— Get the full mechagraph for a subnet mechanismsubnetInfo_getAllMechagraphs— Get mechagraphs for all subnetssubnetInfo_getSelectiveMetagraph— Get filtered metagraph data for specific neuron UIDssubnetInfo_getMetagraph— Get the full metagraph for a subnetneuronInfo_getNeuron— Get detailed info for a single neuron by UID
subnetInfo_getMetagraph - Bittensor RPC Method
Retrieve the SCALE-encoded metagraph for a specific Bittensor subnet. The metagraph is the core network topology data structure containing all validators, miners, stakes, and weights.
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.