# swap_currentAlphaPrice - Bittensor RPC Method

## 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

## Code Examples

### Using SubstrateExamples

## Request Parameters

This method accepts no parameters.

## Request Example

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

## Response Fields

- `result` (`Number, required`): Current ALPHA price as returned by the swap pallet.

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": 1.2
}
```

### 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
  }'
```

## 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.

## Related Methods

- [`swap_simSwapTaoForAlpha`](https://www.dwellir.com/docs/bittensor/swap_simSwapTaoForAlpha) — Simulate swapping TAO for alpha tokens (get estimated output)
- [`swap_simSwapAlphaForTao`](https://www.dwellir.com/docs/bittensor/swap_simSwapAlphaForTao) — Simulate swapping alpha tokens for TAO
- [`subnetInfo_getDynamicInfo`](https://www.dwellir.com/docs/bittensor/subnetInfo_getDynamicInfo) — Get dynamic info including AMM pool state and alpha pricing
- [`subnetInfo_getAllDynamicInfo`](https://www.dwellir.com/docs/bittensor/subnetInfo_getAllDynamicInfo) — Get dynamic info for all subnets
- [`delegateInfo_getDelegates`](https://www.dwellir.com/docs/bittensor/delegateInfo_getDelegates) — Get all delegates (for staking yield comparison)
