Docs

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:

ScenarioRecommended Method
Monitor 1--50 specific neuronsgetSelectiveMechagraph (this method)
Analyze full mechanism topologygetMechagraph
Compare mechanisms for specific neuronsThis method, called once per mecid
Build complete mechanism heatmapsgetMechagraph
Real-time alerting on key neuronsThis method (lower bandwidth per poll)

Parameters

PositionNameTypeRequiredDescription
0netuidu16YesThe subnet identifier
1mecidu16YesThe mechanism identifier within the subnet
2uidsVec<u16>YesArray of neuron UIDs to include in the response
3atBlockHashNoOptional 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:

FieldTypeDescription
netuidu16The subnet identifier
mecidu16The mechanism identifier
nu16Number of neurons in the filtered result
hotkeysVec<AccountId32>Hotkey addresses for the requested neurons
uidsVec<u16>The filtered neuron UIDs
stakeVec<u64>Stake per neuron (RAO). Divide by 1e9 for TAO
trustVec<u16>Mechanism-specific trust scores (0--65535 scaled)
incentiveVec<u16>Mechanism-specific incentive scores (0--65535 scaled)
dividendsVec<u16>Mechanism-specific dividend scores (0--65535 scaled)
emissionVec<u64>Mechanism-specific emissions (RAO per tempo)
weightsVec<Vec<(u16, u16)>>Weight matrix entries for selected neurons
bondsVec<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 weights and bonds matrices 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

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

Python
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

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

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_getSelectiveMechagraph",
    "params": [1, 0, [0, 1, 5, 10], null],
    "id": 1
  }'

Error Handling

Error ScenarioBehaviorRecommended Action
Invalid netuidReturns nullVerify subnet exists via subnetInfo_getSubnetsInfo
Invalid mecidReturns null or emptyMost subnets only have mecid 0
Empty UIDs arrayMay return error or empty resultAlways provide at least one UID
UID out of rangeNeuron data may be omitted or zeroedVerify UIDs exist in the subnet first
Too many UIDsNo hard limit, but large requests approach full mechagraph costFor 50+ UIDs, consider fetching the full mechagraph instead
Invalid block hashReturns JSON-RPC errorVerify 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.