Docs

swap_currentAlphaPrice - Bittensor RPC Method

Retrieve the current alpha token price for a Bittensor subnet. Used for swap calculations, token pricing dashboards, and trading analysis.

Overview

The swap_currentAlphaPrice method returns the current alpha token price for swap calculations on the Bittensor network. In Bittensor's dynamic TAO system, each subnet has its own alpha token that can be swapped for TAO through an automated market maker (AMM) mechanism.

The alpha price represents the current exchange rate between a subnet's alpha token and TAO. This price is determined by the subnet's AMM pool state (alpha reserves and TAO reserves) and changes dynamically as swaps occur.

Note: The shared Dwellir Bittensor endpoint expects a netuid parameter for this call. Handle unsupported subnets or runtime-specific failures as ordinary RPC errors instead of assuming a null response contract.

Understanding Alpha Tokens and Dynamic TAO

In Bittensor's dynamic TAO system, each subnet operates its own internal token called "alpha." This creates a market-driven mechanism for valuing subnets:

  • Alpha tokens represent stake within a specific subnet. When you stake TAO on a dynamic subnet, you receive alpha tokens at the current exchange rate
  • AMM pool: Each subnet has an automated market maker pool containing reserves of both alpha tokens and TAO. The ratio of these reserves determines the price
  • Constant product formula: The pool uses k = alpha_in * tao_in (similar to Uniswap v2). When TAO flows in, alpha flows out, and vice versa
  • Price impact: Large swaps move the price more than small ones due to the constant product formula. The slippage depends on the pool depth
  • Emissions effect: As the subnet earns emissions, TAO flows into the pool, which tends to increase the alpha price over time for well-performing subnets
  • Staking through swaps: Staking TAO on a dynamic subnet effectively swaps TAO for alpha tokens. The alpha tokens represent your share of the subnet's stake pool

Parameters

PositionNameTypeRequiredDescription
0netuidu16YesThe subnet identifier whose alpha price you want to query
1atBlockHashNoOptional block hash for historical pricing. Pass null for the latest state.

Response

FieldTypeDescription
resultnumberThe current scaled alpha price for the requested subnet

The returned value is a runtime-scaled integer. For user-facing displays, pair it with subnetInfo_getDynamicInfo or your existing Bittensor decoder so you interpret the scale factor correctly for the current runtime.

Code Examples

Using SubstrateExamples

Query with Python

Python
import requests
import json

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

payload = {
    'jsonrpc': '2.0',
    'method': 'swap_currentAlphaPrice',
    'params': [1],
    'id': 1
}

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

if result.get('result') is not None:
    alpha_price = result['result']
    print(f'Current alpha price: {alpha_price}')
else:
    print('Alpha price not available (swap pallet may be disabled for this subnet)')

# For subnet-specific pricing, use subnetInfo_getDynamicInfo:
# payload = {
#     'jsonrpc': '2.0',
#     'method': 'subnetInfo_getDynamicInfo',
#     'params': [1, None],
#     'id': 2
# }
# response = requests.post(url, json=payload)
# # Decode SCALE result to get price field

Full Python alpha token analysis

Python
import bittensor as bt
import requests
import json

sub = bt.subtensor(network='finney')
url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'

# Get alpha price from swap RPC
payload = {
    'jsonrpc': '2.0',
    'method': 'swap_currentAlphaPrice',
    'params': [1],
    'id': 1
}
response = requests.post(url, json=payload)
swap_result = response.json()

if swap_result.get('result') is not None:
    print(f"Alpha price (swap RPC): {swap_result['result']}")

# Get detailed alpha pricing from dynamic info for each subnet
netuids = sub.get_all_subnet_netuids()

print(f"\n{'Netuid':>6} {'Dynamic':>8} {'Alpha Price':>14} {'TAO in Pool':>14} {'Alpha in Pool':>14}")
print("-" * 60)

for netuid in netuids[:20]:  # First 20 subnets
    try:
        dyn = sub.get_subnet_dynamic_info(netuid=netuid)
        if dyn and dyn.is_dynamic:
            tao_pool = dyn.tao_in / 1e9
            alpha_pool = dyn.alpha_in / 1e9
            price = tao_pool / alpha_pool if alpha_pool > 0 else 0
            print(f"{netuid:>6} {'Yes':>8} {price:>13,.6f} {tao_pool:>13,.2f} {alpha_pool:>13,.2f}")
        else:
            print(f"{netuid:>6} {'No':>8} {'N/A':>14} {'N/A':>14} {'N/A':>14}")
    except Exception as e:
        print(f"{netuid:>6} Error: {e}")

# Estimate swap output: if you want to swap X TAO for alpha
def estimate_swap_tao_for_alpha(tao_amount, tao_in_pool, alpha_in_pool):
    """Constant product AMM: (tao_in + delta) * (alpha_in - output) = k"""
    k = tao_in_pool * alpha_in_pool
    new_tao = tao_in_pool + tao_amount
    new_alpha = k / new_tao
    alpha_output = alpha_in_pool - new_alpha
    effective_price = tao_amount / alpha_output if alpha_output > 0 else 0
    slippage = (effective_price / (tao_in_pool / alpha_in_pool) - 1) * 100
    return alpha_output, effective_price, slippage

# Example: estimate swapping 100 TAO for alpha on subnet 1
dyn = sub.get_subnet_dynamic_info(netuid=1)
if dyn and dyn.is_dynamic:
    tao_pool = dyn.tao_in / 1e9
    alpha_pool = dyn.alpha_in / 1e9
    swap_amount = 100  # TAO

    alpha_out, eff_price, slippage = estimate_swap_tao_for_alpha(swap_amount, tao_pool, alpha_pool)
    spot_price = tao_pool / alpha_pool

    print(f"\n=== Swap Estimate: {swap_amount} TAO -> Alpha (Subnet 1) ===")
    print(f"Spot price: {spot_price:.6f} TAO/alpha")
    print(f"Alpha received: {alpha_out:,.4f}")
    print(f"Effective price: {eff_price:.6f} TAO/alpha")
    print(f"Price impact: {slippage:.2f}%")

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 });

try {
  const alphaPrice = await api.rpc.swap.currentAlphaPrice(1);
  console.log('Current alpha price:', alphaPrice.toString());
} catch (err) {
  console.log('Swap RPC not available on this node');
}

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": "swap_currentAlphaPrice",
    "params": [1],
    "id": 1
  }'

Error Handling

Error ScenarioBehaviorRecommended Action
Swap pallet not enabledReturns method not found or runtime errorUse subnetInfo_getDynamicInfo as an alternative for alpha pricing data
Unsupported subnet / runtime caseReturns a runtime-defined RPC errorCheck the target netuid and confirm the runtime exposes swap pricing for it
Method not foundError -32601Not all nodes expose swap RPCs; confirm node configuration
Node not syncedMay return stale priceCheck system_health for sync status
Rate limit exceededHTTP 429Cache price data; refresh every few blocks at most

Fallback strategy: If swap_currentAlphaPrice is unavailable, you can calculate the alpha price from subnetInfo_getDynamicInfo using the pool reserves: price = tao_in / alpha_in.

Common Use Cases

  • Subnet token pricing — Display real-time alpha token prices for a specific subnet that uses dynamic TAO pricing.
  • Trading analysis — Monitor alpha price movements to identify trading opportunities between TAO and subnet alpha tokens.
  • Swap UX previews — Show users the current exchange rate before they execute a TAO-to-alpha or alpha-to-TAO swap.
  • Portfolio valuation — Calculate the TAO-equivalent value of alpha token holdings across multiple subnets.
  • Dashboard widgets — Display live price feeds for subnet tokens alongside other network metrics.
  • Slippage estimation — Combine the alpha price with pool depth data from getDynamicInfo to estimate price impact for planned swaps.
  • Arbitrage detection — Compare alpha prices across subnets to identify potential arbitrage opportunities.