---
title: Runtime API Calls
description: Learn how to call Polkadot SDK runtime APIs with the Subxt Rust library to execute logic in the Wasm runtime and retrieve computed results.
categories: Protocol Internals, Tooling
url: https://docs.parity.io/tools/chain-interactions/query-data/runtime-api-calls/
word_count: 845
token_estimate: 1606
version_hash: sha256:c742ddab27ca0b49d3ade9feccccc8e7f987c3bdd997648f61c33f227d55e2c0
last_updated: 2026-11-17T16:28:58+00:00
---

# Runtime API Calls

## Introduction

Polkadot SDK runtime APIs provide direct access to the blockchain's WebAssembly (Wasm) runtime, enabling specialized queries and computations that go beyond simple storage reads. Unlike storage queries that fetch static data, runtime APIs execute logic within the runtime to compute results dynamically.

Common runtime APIs include:

- **`AccountNonceApi`**: Retrieves the current transaction nonce for an account.
- **`Metadata`**: Queries available metadata versions and runtime information.
- **`TransactionPaymentApi`**: Estimates transaction fees before submission.

Runtimes expose additional APIs for the pallets they include. For example, a runtime with staking pallets exposes staking-related APIs.

## Call Runtime APIs with Subxt

This section uses [Subxt](/tools/subxt.md), Parity's Rust library for Polkadot SDK-based chains, to call runtime APIs on a local development node. The example queries an account nonce and the supported metadata versions.

The same runtime APIs can be called from third-party client libraries, for example [Polkadot API (PAPI)](https://developers.polkadot.com/reference/tools/papi/), [Dedot](https://developers.polkadot.com/reference/tools/dedot/), [Polkadot.js API](https://developers.polkadot.com/reference/tools/polkadot-js-api/), and [Python Substrate Interface](https://developers.polkadot.com/reference/tools/py-substrate-interface/).

### Prerequisites

- [Rust](https://rustup.rs/) toolchain (latest stable) and Cargo.
- A local development node listening on `ws://127.0.0.1:9944`, for example the parachain template node described in [Run the Node Locally](/polkadot-sdk/launch-a-parachain/set-up-the-parachain-template.md#run-the-node-locally).

### Set Up the Project

1. Create a new Rust project:

    ```bash
    cargo new subxt-runtime-api-example && cd subxt-runtime-api-example
    ```

2. Install the Subxt CLI:

    ```bash
    cargo install subxt-cli@0.50.1
    ```

3. Download the metadata from your local node:

    ```bash
    subxt metadata --url ws://127.0.0.1:9944 -o metadata.scale
    ```

    To target a different chain, pass its WebSocket endpoint to `--url` and update the `NODE_URL` constant in the example to match.

4. Update `Cargo.toml` with the required dependencies:

    ```toml title="Cargo.toml"
    [package]
    name = "subxt-runtime-api-example"
    version = "0.1.0"
    edition = "2021"
    
    [[bin]]
    name = "runtime_apis"
    path = "src/bin/runtime_apis.rs"
    
    [dependencies]
    subxt = "0.50.1"
    tokio = { version = "1", features = ["rt", "macros"] }
    
    ```

### Call the APIs

The following example demonstrates calling two runtime APIs:

- **`AccountNonceApi.account_nonce`**: Gets the current nonce using the static interface generated from metadata.
- **`Metadata.metadata_versions`**: Retrieves supported metadata versions using the dynamic interface.

Create a file at `src/bin/runtime_apis.rs` and add the following code:

```rust title="src/bin/runtime_apis.rs"
use std::str::FromStr;
use subxt::dynamic::Value;
use subxt::utils::AccountId32;
use subxt::{OnlineClient, PolkadotConfig};

// Generate an interface from the node's metadata
#[subxt::subxt(runtime_metadata_path = "metadata.scale")]
pub mod runtime {}

// WebSocket endpoint of your local development node
const NODE_URL: &str = "ws://127.0.0.1:9944";

// Address to query (Alice's development account by default)
const ADDRESS: &str = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the Subxt client
    let api = OnlineClient::<PolkadotConfig>::from_url(NODE_URL).await?;

    // Anchor to the current block
    let at_block = api.at_current_block().await?;

    println!("Connected to {}", NODE_URL);
    println!("Querying runtime APIs for: {}\n", ADDRESS);

    // Parse the address
    let account = AccountId32::from_str(ADDRESS)?;

    // Call AccountNonceApi using static interface
    let nonce_call = runtime::runtime_apis()
        .account_nonce_api()
        .account_nonce(account.clone());
    let nonce = at_block.runtime_apis().call(nonce_call).await?;
    println!("AccountNonceApi Results:");
    println!("  Account Nonce: {}", nonce);

    // Call Metadata API to get supported versions using dynamic call
    let metadata_versions_call =
        subxt::dynamic::runtime_api_call::<_, Value>("Metadata", "metadata_versions", ());
    let versions_result = at_block
        .runtime_apis()
        .call(metadata_versions_call)
        .await?;
    println!("\nMetadata API Results:");
    println!(
        "  Supported Metadata Versions: {}",
        versions_result
    );

    Ok(())
}

```

By default, the example queries Alice's development account. Replace the `ADDRESS` value to query a different account. Then run the script:

```bash
cargo run --bin runtime_apis
```

The script prints the account nonce and the list of metadata versions that the runtime supports.

## Available Runtime APIs

The following runtime APIs are commonly available on Polkadot SDK-based chains:

| API | Description |
|-----|-------------|
| `AccountNonceApi` | Get current transaction nonce for an account |
| `TransactionPaymentApi` | Query transaction fees and weight information |
| `TransactionPaymentCallApi` | Estimate fees for a call without creating an extrinsic |
| `Metadata` | Query metadata versions and runtime metadata |
| `BlockBuilder` | Access block building functionality |
| `Core` | Core runtime version and execution |
| `TaggedTransactionQueue` | Validate transactions in the pool |
| `OffchainWorkerApi` | Offchain worker functionality |
| `SessionKeys` | Session key management |
| `GrandpaApi` | GRANDPA finality information |
| `BabeApi` | BABE consensus information |

!!! note
    Available runtime APIs vary by chain. Check your target chain's metadata to see which APIs are exposed.

## Where to Go Next

Now that you understand how to call runtime APIs to execute logic within the runtime, explore these related topics:

<div class="grid cards" markdown>

-   __Query with SDKs__

    ---

    Use the Subxt Rust library to query storage.

    [:octicons-arrow-right-24: Get Started](/tools/chain-interactions/query-data/query-sdks.md)

-   __Query On-Chain State with Polkadot REST API__

    ---

    Learn how to query on-chain state using the Polkadot REST API.

    [:octicons-arrow-right-24: Get Started](/tools/chain-interactions/query-data/query-rest.md)

-   __Send Transactions__

    ---

    Learn to construct and submit transactions.

    [:octicons-arrow-right-24: Get Started](/tools/chain-interactions/send-transactions/with-sdks.md)

</div>
