subnetInfo_getAllMetagraphs - Bittensor RPC Method
Retrieve SCALE-encoded metagraphs for all Bittensor subnets in a single call. Essential for network-wide analytics, cross-subnet comparisons, and global monitoring dashboards.
Overview
The subnetInfo_getAllMetagraphs method returns the SCALE-encoded metagraphs for every active subnet on the Bittensor network in a single RPC call. This is the bulk equivalent of calling subnetInfo_getMetagraph for each netuid individually.
Each metagraph contains the complete topology of a subnet: all registered neurons, their stakes, trust scores, incentive values, weight matrices, emission distributions, and axon endpoints. By fetching all metagraphs at once, you can efficiently perform cross-subnet analysis and build network-wide monitoring dashboards.
Note: This method returns a large payload since it includes metagraph data for every active subnet. Expect response sizes in the range of several megabytes for networks with many subnets. Consider using
subnetInfo_getMetagraphfor targeted single-subnet queries when you only need specific data.
Parameters
| Position | Name | Type | Required | Description |
|---|---|---|---|---|
| 0 | 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 returns a vector of metagraph structures, one per active subnet. Each metagraph contains:
| Field | Type | Description |
|---|---|---|
netuid | u16 | The subnet identifier |
n | u16 | Number of neurons registered |
block | u64 | Block number at capture time |
hotkeys | Vec<AccountId32> | Hotkey addresses for every neuron |
coldkeys | Vec<AccountId32> | Coldkey (owner) addresses |
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 |
weights | Vec<Vec<(u16, u16)>> | Weight matrix (sparse: uid, weight pairs) |
bonds | Vec<Vec<(u16, u16)>> | Bond matrix (sparse: uid, bond pairs) |
axons | Vec<AxonInfo> | Network endpoint info (IP, port, protocol) |
SCALE Decoding
The response decodes to Vec<MetagraphInfo>, where each MetagraphInfo contains the fields above. Due to the size of this response, decoding can be computationally intensive.
Using @polkadot/api: Register all Bittensor types including MetagraphInfo and AxonInfo before calling. The decoded result is an array that can be iterated. Each element has the same structure as the single subnetInfo_getMetagraph response.
Using bittensor Python SDK: There is no single SDK call that returns all metagraphs at once. Instead, iterate over subnet netuids: for netuid in sub.get_all_subnet_netuids(): meta = sub.metagraph(netuid=netuid). For the raw RPC approach, decode Vec<MetagraphInfo> using the Bittensor type registry.
Performance notes:
- The total payload can exceed 10 MB for networks with 30+ active subnets
- Decoding time scales linearly with the number of subnets and neurons
- Consider processing the response in a background thread to avoid blocking your main application
- Cache the result and refresh at a cadence appropriate for your use case (once per tempo or less frequently)
Code Examples
Using SubstrateExamples
Decode with Python
import requests
import json
url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'
payload = {
'jsonrpc': '2.0',
'method': 'subnetInfo_getAllMetagraphs',
'params': [None],
'id': 1
}
response = requests.post(url, json=payload, timeout=60)
result = response.json()
if result.get('result'):
scale_bytes = result['result']
print(f'All metagraphs SCALE data size: {len(scale_bytes)} bytes')
print(f'Approximate size: {len(scale_bytes) // 2 / 1024:.1f} KB')
else:
print('No metagraphs returned')
# To decode with bittensor SDK:
# import bittensor as bt
# sub = bt.subtensor(network='finney')
# for netuid in sub.get_all_subnet_netuids():
# meta = sub.metagraph(netuid=netuid)
# print(f"Subnet {netuid}: {meta.n} neurons, emissions: {meta.E.sum():.4f}")Full Python cross-subnet analysis
import bittensor as bt
import numpy as np
sub = bt.subtensor(network='finney')
netuids = sub.get_all_subnet_netuids()
print(f"{'Netuid':>6} {'Neurons':>8} {'Validators':>11} {'Total Stake':>15} {'Emissions':>12} {'Avg Trust':>10}")
print("-" * 66)
total_neurons = 0
total_stake = 0
for netuid in netuids:
try:
meta = sub.metagraph(netuid=netuid)
n_validators = sum(meta.validator_permit)
total_s = meta.S.sum()
total_e = meta.E.sum()
avg_trust = meta.T.mean()
total_neurons += meta.n
total_stake += total_s
print(f"{netuid:>6} {meta.n:>8} {n_validators:>11} {total_s:>14,.2f} {total_e:>11,.4f} {avg_trust:>9,.4f}")
except Exception as e:
print(f"{netuid:>6} Error: {e}")
print("-" * 66)
print(f"Total neurons: {total_neurons}, Total stake: {total_stake:,.2f} TAO")
# Find hotkeys registered on multiple subnets
hotkey_subnets = {}
for netuid in netuids:
meta = sub.metagraph(netuid=netuid)
for uid in range(meta.n):
hk = meta.hotkeys[uid]
hotkey_subnets.setdefault(hk, []).append(netuid)
multi_subnet = {k: v for k, v in hotkey_subnets.items() if len(v) > 1}
print(f"\nHotkeys on multiple subnets: {len(multi_subnet)}")
for hk, nets in sorted(multi_subnet.items(), key=lambda x: len(x[1]), reverse=True)[:5]:
print(f" {hk[:18]}.. on subnets: {nets}")Decode 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 });
const allMetagraphs = await api.rpc.subnetInfo.getAllMetagraphs();
console.log('Raw data size:', allMetagraphs.toHex().length, 'bytes');
// With Bittensor type definitions registered, iterate decoded metagraphs
// for (const meta of allMetagraphs) {
// console.log(`Subnet ${meta.netuid}: ${meta.n} neurons`);
// }
await api.disconnect();Error Handling
| Error Scenario | Behavior | Recommended Action |
|---|---|---|
| Response too large | Connection may timeout or drop | Increase HTTP/WebSocket timeout to 60+ seconds |
| Node memory limits | Node may reject the request | Fall back to individual getMetagraph calls per subnet |
| Node not synced | Returns partial or stale data | Check system_health before making bulk queries |
| Invalid block hash | Returns JSON-RPC error | Verify the block hash exists on chain |
| Rate limit exceeded | HTTP 429 | Cache results aggressively; this data changes slowly |
Best practices:
- Set an HTTP timeout of at least 60 seconds for this call
- Process the response asynchronously to avoid blocking your application
- Cache the result and refresh only when needed (e.g., every 5--10 minutes)
- If you only need a few subnets, prefer
subnetInfo_getMetagraphwith specific netuids
Common Use Cases
- Network-wide analytics — Build dashboards that aggregate neuron counts, total stake, emission distributions, and health metrics across all subnets.
- Cross-subnet comparisons — Compare validator performance, miner incentive scores, and consensus quality between subnets.
- Global monitoring — Track network growth by monitoring how many neurons are registered across all subnets over time.
- Emission analysis — Visualize how TAO emissions are distributed across subnets and identify which subnets receive the most rewards.
- Research — Study the global network topology and how different subnet configurations affect incentive dynamics.
- Multi-subnet operators — Monitor all your neurons across subnets in a single query instead of making individual calls.
Related Methods
subnetInfo_getMetagraph— Get metagraph for a single subnet (lighter response)subnetInfo_getSelectiveMetagraph— Get filtered metagraph data for specific neuron UIDssubnetInfo_getSubnetsInfo— Get configuration info for all subnetssubnetInfo_getAllDynamicInfo— Get dynamic info for all subnetssubnetInfo_getAllMechagraphs— Get mechagraphs for all subnets
subnetInfo_getAllMechagraphs - JSON-RPC Me...
Fetch SCALE-encoded mechagraphs for all subnets on Bittensor.
subnetInfo_getColdkeyAutoStakeHotkey - Bittensor RPC Method
Retrieve the auto-stake hotkey configured for a coldkey on a Bittensor subnet. Used for staking automation, delegation management, and validator operations.