From 19bcea71665701ecadfb4b646815400d01d50d72 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Thu, 11 Dec 2025 14:04:41 +0700 Subject: [PATCH 1/9] Add runtime API calls guide with SDK examples Add comprehensive guide for calling runtime APIs using PAPI, Polkadot.js, Dedot, Python Substrate Interface, and Subxt. Examples demonstrate AccountNonceApi and Metadata runtime API calls with complete, tested code snippets for each SDK. --- .../query-data/runtime-api-calls.md | 338 +++++++++++++++++- .../dedot/runtime-apis-ts.html | 12 + .../runtime-api-calls/dedot/runtime-apis.ts | 31 ++ .../papi/runtime-apis-ts.html | 12 + .../runtime-api-calls/papi/runtime-apis.ts | 37 ++ .../pjs/runtime-apis-js.html | 12 + .../runtime-api-calls/pjs/runtime-apis.js | 34 ++ .../psi/runtime-apis-py.html | 14 + .../runtime-api-calls/psi/runtime_apis.py | 33 ++ .../runtime-api-calls/subxt/Cargo.toml | 12 + .../subxt/runtime-apis-rs.html | 12 + .../subxt/src/bin/runtime_apis.rs | 50 +++ 12 files changed, 596 insertions(+), 1 deletion(-) create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/Cargo.toml create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html create mode 100644 .snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs diff --git a/.chain-interactions/query-data/runtime-api-calls.md b/.chain-interactions/query-data/runtime-api-calls.md index 30404ce4c..9d9475339 100644 --- a/.chain-interactions/query-data/runtime-api-calls.md +++ b/.chain-interactions/query-data/runtime-api-calls.md @@ -1 +1,337 @@ -TODO \ No newline at end of file +--- +title: Runtime API Calls +description: Learn how to call runtime APIs on Polkadot Hub using PAPI, Polkadot.js, Dedot, Python Substrate Interface, and Subxt. +categories: Chain Interactions +--- + +# 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 +- **NominationPoolsApi** - retrieves staking pool information and pending rewards +- **StakingApi** - accesses staking-related computations + +This guide demonstrates how to call runtime APIs using five popular SDKs: + +- **[Polkadot API (PAPI)](/reference/tools/papi/){target=\_blank}** - modern TypeScript library with type-safe APIs +- **[Polkadot.js API](/reference/tools/polkadot-js-api/){target=\_blank}** - comprehensive JavaScript library (maintenance mode) +- **[Dedot](/reference/tools/dedot/){target=\_blank}** - lightweight TypeScript library optimized for performance +- **[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank}** - Python library for Substrate chains +- **[Subxt](/reference/tools/subxt/){target=\_blank}** - Rust library with compile-time type safety + +Select your preferred SDK below to see complete, runnable examples that query Polkadot Hub for account nonces and metadata information. + +## Call Runtime APIs + +=== "PAPI" + + **Prerequisites** + + - [Node.js](https://nodejs.org/){target=\_blank} v18 or higher + - npm, pnpm, or yarn package manager + + **Environment Setup** + + 1. Create and initialize a new project: + + ```bash + mkdir papi-runtime-api-example && cd papi-runtime-api-example && \ + npm init -y && npm pkg set type=module + ``` + + 2. Install dependencies: + + ```bash + npm install polkadot-api && \ + npm install --save-dev @types/node tsx typescript + ``` + + 3. Generate types for Polkadot Hub: + + ```bash + npx papi add pah -n polkadot_asset_hub + ``` + + **Call Runtime APIs** + + The following example demonstrates calling several runtime APIs: + + - `AccountNonceApi.account_nonce` - gets the current nonce for an account + - `Metadata.metadata_versions` - retrieves supported metadata versions + + Create a file named `runtime-apis.ts` and add the following code: + + ```typescript title="runtime-apis.ts" + --8<-- "code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts" + ``` + + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + + Run the script: + + ```bash + npx tsx runtime-apis.ts + ``` + + You should see output similar to: + + --8<-- 'code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html' + +=== "Polkadot.js" + + !!! warning "Maintenance Mode Only" + The Polkadot.js API is no longer actively developed. New projects should use [PAPI](/reference/tools/papi/){target=\_blank} or [Dedot](/reference/tools/dedot/){target=\_blank} as actively maintained alternatives. + + **Prerequisites** + + - [Node.js](https://nodejs.org/){target=\_blank} v18 or higher + - npm, pnpm, or yarn package manager + + **Environment Setup** + + 1. Create and initialize a new project: + + ```bash + mkdir pjs-runtime-api-example && cd pjs-runtime-api-example && \ + npm init -y && npm pkg set type=module + ``` + + 2. Install dependencies: + + ```bash + npm install @polkadot/api + ``` + + **Call Runtime APIs** + + The following example demonstrates calling several runtime APIs: + + - `accountNonceApi.accountNonce` - gets the current nonce for an account + - `metadata.metadataVersions` - retrieves supported metadata versions + + Create a file named `runtime-apis.js` and add the following code: + + ```javascript title="runtime-apis.js" + --8<-- "code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js" + ``` + + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + + Run the script: + + ```bash + node runtime-apis.js + ``` + + You should see output similar to: + + --8<-- 'code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html' + +=== "Dedot" + + **Prerequisites** + + - [Node.js](https://nodejs.org/){target=\_blank} v18 or higher + - npm, pnpm, or yarn package manager + + **Environment Setup** + + 1. Create and initialize a new project: + + ```bash + mkdir dedot-runtime-api-example && cd dedot-runtime-api-example && \ + npm init -y && npm pkg set type=module + ``` + + 2. Install dependencies: + + ```bash + npm install dedot && \ + npm install --save-dev @dedot/chaintypes @types/node tsx typescript + ``` + + **Call Runtime APIs** + + The following example demonstrates calling several runtime APIs: + + - `accountNonceApi.accountNonce` - gets the current nonce for an account + - `metadata.metadataVersions` - retrieves supported metadata versions + + Create a file named `runtime-apis.ts` and add the following code: + + ```typescript title="runtime-apis.ts" + --8<-- "code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts" + ``` + + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + + Run the script: + + ```bash + npx tsx runtime-apis.ts + ``` + + You should see output similar to: + + --8<-- 'code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html' + +=== "Py Substrate Interface" + + **Prerequisites** + + - [Python](https://www.python.org/){target=\_blank} 3.8 or higher + - pip package manager + + **Environment Setup** + + 1. Create a new project directory and set up a virtual environment: + + ```bash + mkdir psi-runtime-api-example && cd psi-runtime-api-example && \ + python3 -m venv venv && source venv/bin/activate + ``` + + 2. Install the substrate-interface package: + + ```bash + pip install substrate-interface + ``` + + **Call Runtime APIs** + + The following example demonstrates calling several runtime APIs: + + - `AccountNonceApi.account_nonce` - gets the current nonce for an account + - `Core.version` - retrieves runtime version information + + Create a file named `runtime_apis.py` and add the following code: + + ```python title="runtime_apis.py" + --8<-- "code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py" + ``` + + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + + Run the script: + + ```bash + python runtime_apis.py + ``` + + You should see output similar to: + + --8<-- 'code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html' + +=== "Subxt" + + [Subxt](/reference/tools/subxt/){target=\_blank} is a Rust library that provides compile-time type safety through code generation from chain metadata. + + **Prerequisites** + + - [Rust](https://rustup.rs/){target=\_blank} toolchain (latest stable) + - Cargo package manager + + **Environment Setup** + + 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@{{ dependencies.crates.subxt_cli.version }} + ``` + + 3. Download the Polkadot Hub metadata: + + ```bash + subxt metadata --url INSERT_WS_ENDPOINT -o asset_hub_metadata.scale + ``` + + Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://polkadot-asset-hub-rpc.polkadot.io` for Polkadot Hub. + + 4. Update `Cargo.toml` with the required dependencies: + + ```toml title="Cargo.toml" + --8<-- "code/chain-interactions/query-data/runtime-api-calls/subxt/Cargo.toml" + ``` + + **Call Runtime APIs** + + The following example demonstrates calling several runtime APIs: + + - `AccountNonceApi.account_nonce` - gets the current nonce using the static interface + - `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" + --8<-- "code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs" + ``` + + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + + Run the script: + + ```bash + cargo run --bin runtime_apis + ``` + + You should see output similar to: + + --8<-- 'code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html' + +## 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 | +| `NominationPoolsApi` | Nomination pools data and pending rewards | +| `StakingApi` | Staking-related computations | + +!!! note + Available runtime APIs vary by chain. Check your target chain's metadata to see which APIs are exposed. + +## Where to Go Next + +
+ +- Guide **Query On-Chain State** + + --- + + Learn how to query storage data from the blockchain. + + [:octicons-arrow-right-24: Get Started](/chain-interactions/query-data/query-sdks/) + +- Guide **Send Transactions** + + --- + + Learn how to construct and submit transactions. + + [:octicons-arrow-right-24: Get Started](/chain-interactions/send-transactions/with-sdks/) + +
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html new file mode 100644 index 000000000..8d55111e6 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html @@ -0,0 +1,12 @@ +
+ npx tsx runtime-apis.ts + + Connected to Polkadot Hub + Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 + + AccountNonceApi Results: + Account Nonce: 11 + + Metadata API Results: + Supported Metadata Versions: [14, 15, 16] +
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts new file mode 100644 index 000000000..d87ff732f --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts @@ -0,0 +1,31 @@ +import { DedotClient, WsProvider } from 'dedot'; +import type { PolkadotAssetHubApi } from '@dedot/chaintypes'; + +const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; + +// Example address to query (Polkadot Hub address) +const ADDRESS = 'INSERT_ADDRESS'; + +async function main() { + // Initialize provider and client with Asset Hub types + const provider = new WsProvider(ASSET_HUB_RPC); + const client = await DedotClient.new(provider); + + console.log('Connected to Polkadot Hub'); + console.log(`Querying runtime APIs for: ${ADDRESS}\n`); + + // Call AccountNonceApi to get the account nonce + const nonce = await client.call.accountNonceApi.accountNonce(ADDRESS); + console.log('AccountNonceApi Results:'); + console.log(` Account Nonce: ${nonce}`); + + // Query metadata versions using Metadata runtime API + const metadataVersions = await client.call.metadata.metadataVersions(); + console.log('\nMetadata API Results:'); + console.log(` Supported Metadata Versions: [${metadataVersions.join(', ')}]`); + + // Disconnect the client + await client.disconnect(); +} + +main().catch(console.error); diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html new file mode 100644 index 000000000..8d55111e6 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html @@ -0,0 +1,12 @@ +
+ npx tsx runtime-apis.ts + + Connected to Polkadot Hub + Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 + + AccountNonceApi Results: + Account Nonce: 11 + + Metadata API Results: + Supported Metadata Versions: [14, 15, 16] +
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts new file mode 100644 index 000000000..7da625ef1 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts @@ -0,0 +1,37 @@ +import { createClient } from 'polkadot-api'; +import { getWsProvider } from 'polkadot-api/ws-provider/node'; +import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat'; +import { pah } from '@polkadot-api/descriptors'; + +const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; + +// Example address to query (Polkadot Hub address) +const ADDRESS = 'INSERT_ADDRESS'; + +async function main() { + // Create the client connection + const client = createClient( + withPolkadotSdkCompat(getWsProvider(ASSET_HUB_RPC)) + ); + + // Get the typed API for Polkadot Hub + const api = client.getTypedApi(pah); + + console.log('Connected to Polkadot Hub'); + console.log(`Querying runtime APIs for: ${ADDRESS}\n`); + + // Call AccountNonceApi to get the account nonce + const nonce = await api.apis.AccountNonceApi.account_nonce(ADDRESS); + console.log('AccountNonceApi Results:'); + console.log(` Account Nonce: ${nonce}`); + + // Query metadata versions using Metadata runtime API + const metadataVersions = await api.apis.Metadata.metadata_versions(); + console.log('\nMetadata API Results:'); + console.log(` Supported Metadata Versions: [${metadataVersions.join(', ')}]`); + + // Disconnect the client + client.destroy(); +} + +main().catch(console.error); diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html new file mode 100644 index 000000000..e19552493 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html @@ -0,0 +1,12 @@ +
+ node runtime-apis.js + + Connected to Polkadot Hub + Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 + + AccountNonceApi Results: + Account Nonce: 11 + + Metadata API Results: + Supported Metadata Versions: [14, 15, 16] +
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js new file mode 100644 index 000000000..63a886b1d --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js @@ -0,0 +1,34 @@ +import { ApiPromise, WsProvider } from '@polkadot/api'; + +const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; + +// Example address to query (Polkadot Hub address) +const ADDRESS = 'INSERT_ADDRESS'; + +async function main() { + // Create a WebSocket provider + const wsProvider = new WsProvider(ASSET_HUB_RPC); + + // Initialize the API + const api = await ApiPromise.create({ provider: wsProvider }); + + console.log('Connected to Polkadot Hub'); + console.log(`Querying runtime APIs for: ${ADDRESS}\n`); + + // Call AccountNonceApi to get the account nonce + const nonce = await api.call.accountNonceApi.accountNonce(ADDRESS); + console.log('AccountNonceApi Results:'); + console.log(` Account Nonce: ${nonce.toString()}`); + + // Query metadata versions using Metadata runtime API + const metadataVersions = await api.call.metadata.metadataVersions(); + console.log('\nMetadata API Results:'); + console.log( + ` Supported Metadata Versions: [${metadataVersions.map((v) => v.toString()).join(', ')}]` + ); + + // Disconnect from the node + await api.disconnect(); +} + +main().catch(console.error); diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html new file mode 100644 index 000000000..fd8bdf448 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html @@ -0,0 +1,14 @@ +
+ python runtime_apis.py + + Connected to Polkadot Hub + Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 + + AccountNonceApi Results: + Account Nonce: 11 + + Core API Results: + Spec Name: statemint + Spec Version: 2000003 + Impl Version: 0 +
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py new file mode 100644 index 000000000..28b718ffa --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py @@ -0,0 +1,33 @@ +from substrateinterface import SubstrateInterface + +ASSET_HUB_RPC = "INSERT_WS_ENDPOINT" + +# Example address to query (Polkadot Hub address) +ADDRESS = "INSERT_ADDRESS" + + +def main(): + # Connect to Polkadot Hub + substrate = SubstrateInterface(url=ASSET_HUB_RPC) + + print("Connected to Polkadot Hub") + print(f"Querying runtime APIs for: {ADDRESS}\n") + + # Call AccountNonceApi to get the account nonce + nonce = substrate.runtime_call("AccountNonceApi", "account_nonce", [ADDRESS]) + print("AccountNonceApi Results:") + print(f" Account Nonce: {nonce.value}") + + # Query runtime version using Core runtime API + version = substrate.runtime_call("Core", "version", []) + print("\nCore API Results:") + print(f" Spec Name: {version.value['spec_name']}") + print(f" Spec Version: {version.value['spec_version']}") + print(f" Impl Version: {version.value['impl_version']}") + + # Close connection + substrate.close() + + +if __name__ == "__main__": + main() diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/Cargo.toml b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/Cargo.toml new file mode 100644 index 000000000..70123cc97 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/Cargo.toml @@ -0,0 +1,12 @@ +[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.44.0" +tokio = { version = "1", features = ["rt", "macros"] } diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html new file mode 100644 index 000000000..caa76b686 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html @@ -0,0 +1,12 @@ +
+ cargo run --bin runtime_apis + + Connected to Polkadot Hub + Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 + + AccountNonceApi Results: + Account Nonce: 11 + + Metadata API Results: + Supported Metadata Versions: (14, 15, 16) +
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs new file mode 100644 index 000000000..aaf2f2916 --- /dev/null +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs @@ -0,0 +1,50 @@ +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 = "asset_hub_metadata.scale")] +pub mod asset_hub {} + +const ASSET_HUB_RPC: &str = "INSERT_WS_ENDPOINT"; + +// Example address to query (Polkadot Hub address) +const ADDRESS: &str = "INSERT_ADDRESS"; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> Result<(), Box> { + // Initialize the Subxt client + let api = OnlineClient::::from_url(ASSET_HUB_RPC).await?; + + println!("Connected to Polkadot Hub"); + println!("Querying runtime APIs for: {}\n", ADDRESS); + + // Parse the address + let account = AccountId32::from_str(ADDRESS)?; + + // Call AccountNonceApi using static interface + let nonce_call = asset_hub::apis() + .account_nonce_api() + .account_nonce(account.clone()); + let nonce = api.runtime_api().at_latest().await?.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("Metadata", "metadata_versions", Vec::::new()); + let versions_result = api + .runtime_api() + .at_latest() + .await? + .call(metadata_versions_call) + .await?; + println!("\nMetadata API Results:"); + println!( + " Supported Metadata Versions: {}", + versions_result.to_value()? + ); + + Ok(()) +} From 383da31c5465da37098c975595c52cd4e28dc353 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Fri, 12 Dec 2025 13:53:08 +0700 Subject: [PATCH 2/9] Refactor runtime API calls guide to use Polkadot Hub TestNet - Update all examples to use Paseo Asset Hub endpoint (wss://asset-hub-paseo.dotters.network) - Change PAPI types generation to use polkadotTestNet descriptor - Update console output messages to show "Connected to Polkadot Hub TestNet" - Update HTML output snippets to reflect testnet connection - Update Python output to show asset-hub-paseo spec name --- .../query-data/runtime-api-calls.md | 22 +++++++++---------- .../dedot/runtime-apis-ts.html | 2 +- .../runtime-api-calls/dedot/runtime-apis.ts | 4 ++-- .../papi/runtime-apis-ts.html | 2 +- .../runtime-api-calls/papi/runtime-apis.ts | 10 ++++----- .../pjs/runtime-apis-js.html | 2 +- .../runtime-api-calls/pjs/runtime-apis.js | 4 ++-- .../psi/runtime-apis-py.html | 6 ++--- .../runtime-api-calls/psi/runtime_apis.py | 6 ++--- .../subxt/runtime-apis-rs.html | 2 +- .../subxt/src/bin/runtime_apis.rs | 4 ++-- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.chain-interactions/query-data/runtime-api-calls.md b/.chain-interactions/query-data/runtime-api-calls.md index 9d9475339..37ca386f3 100644 --- a/.chain-interactions/query-data/runtime-api-calls.md +++ b/.chain-interactions/query-data/runtime-api-calls.md @@ -1,6 +1,6 @@ --- title: Runtime API Calls -description: Learn how to call runtime APIs on Polkadot Hub using PAPI, Polkadot.js, Dedot, Python Substrate Interface, and Subxt. +description: Learn how to call runtime APIs on Polkadot using PAPI, Polkadot.js, Dedot, Python Substrate Interface, and Subxt. categories: Chain Interactions --- @@ -26,7 +26,7 @@ This guide demonstrates how to call runtime APIs using five popular SDKs: - **[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank}** - Python library for Substrate chains - **[Subxt](/reference/tools/subxt/){target=\_blank}** - Rust library with compile-time type safety -Select your preferred SDK below to see complete, runnable examples that query Polkadot Hub for account nonces and metadata information. +Select your preferred SDK below to see complete, runnable examples that query Polkadot Hub TestNet (Paseo Asset Hub) for account nonces and metadata information. ## Call Runtime APIs @@ -53,10 +53,10 @@ Select your preferred SDK below to see complete, runnable examples that query Po npm install --save-dev @types/node tsx typescript ``` - 3. Generate types for Polkadot Hub: + 3. Generate types for Polkadot Hub TestNet: ```bash - npx papi add pah -n polkadot_asset_hub + npx papi add polkadotTestNet -w wss://asset-hub-paseo.dotters.network ``` **Call Runtime APIs** @@ -72,7 +72,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po --8<-- "code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts" ``` - Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query. Run the script: @@ -122,7 +122,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po --8<-- "code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js" ``` - Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query. Run the script: @@ -170,7 +170,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po --8<-- "code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts" ``` - Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query. Run the script: @@ -217,7 +217,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po --8<-- "code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py" ``` - Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query. Run the script: @@ -252,13 +252,13 @@ Select your preferred SDK below to see complete, runnable examples that query Po cargo install subxt-cli@{{ dependencies.crates.subxt_cli.version }} ``` - 3. Download the Polkadot Hub metadata: + 3. Download the Polkadot Hub TestNet metadata: ```bash subxt metadata --url INSERT_WS_ENDPOINT -o asset_hub_metadata.scale ``` - Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://polkadot-asset-hub-rpc.polkadot.io` for Polkadot Hub. + Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://asset-hub-paseo.dotters.network` for Polkadot Hub TestNet (Paseo Asset Hub). 4. Update `Cargo.toml` with the required dependencies: @@ -279,7 +279,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po --8<-- "code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs" ``` - Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://polkadot-asset-hub-rpc.polkadot.io`) and `INSERT_ADDRESS` with the account address you want to query. + Ensure to replace `INSERT_WS_ENDPOINT` with a valid WebSocket endpoint (e.g., `wss://asset-hub-paseo.dotters.network`) and `INSERT_ADDRESS` with the account address you want to query. Run the script: diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html index 8d55111e6..e04b71118 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis-ts.html @@ -1,7 +1,7 @@
npx tsx runtime-apis.ts - Connected to Polkadot Hub + Connected to Polkadot Hub TestNet Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 AccountNonceApi Results: diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts index d87ff732f..c19f4252c 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts @@ -3,7 +3,7 @@ import type { PolkadotAssetHubApi } from '@dedot/chaintypes'; const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; -// Example address to query (Polkadot Hub address) +// Example address to query const ADDRESS = 'INSERT_ADDRESS'; async function main() { @@ -11,7 +11,7 @@ async function main() { const provider = new WsProvider(ASSET_HUB_RPC); const client = await DedotClient.new(provider); - console.log('Connected to Polkadot Hub'); + console.log('Connected to Polkadot Hub TestNet'); console.log(`Querying runtime APIs for: ${ADDRESS}\n`); // Call AccountNonceApi to get the account nonce diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html index 8d55111e6..e04b71118 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis-ts.html @@ -1,7 +1,7 @@
npx tsx runtime-apis.ts - Connected to Polkadot Hub + Connected to Polkadot Hub TestNet Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 AccountNonceApi Results: diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts index 7da625ef1..4b28d8b99 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts @@ -1,11 +1,11 @@ import { createClient } from 'polkadot-api'; import { getWsProvider } from 'polkadot-api/ws-provider/node'; import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat'; -import { pah } from '@polkadot-api/descriptors'; +import { polkadotTestNet } from '@polkadot-api/descriptors'; const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; -// Example address to query (Polkadot Hub address) +// Example address to query const ADDRESS = 'INSERT_ADDRESS'; async function main() { @@ -14,10 +14,10 @@ async function main() { withPolkadotSdkCompat(getWsProvider(ASSET_HUB_RPC)) ); - // Get the typed API for Polkadot Hub - const api = client.getTypedApi(pah); + // Get the typed API for Polkadot Hub TestNet (Paseo Asset Hub) + const api = client.getTypedApi(polkadotTestNet); - console.log('Connected to Polkadot Hub'); + console.log('Connected to Polkadot Hub TestNet'); console.log(`Querying runtime APIs for: ${ADDRESS}\n`); // Call AccountNonceApi to get the account nonce diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html index e19552493..d828e1fdc 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis-js.html @@ -1,7 +1,7 @@
node runtime-apis.js - Connected to Polkadot Hub + Connected to Polkadot Hub TestNet Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 AccountNonceApi Results: diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js index 63a886b1d..f7f33c38c 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js @@ -2,7 +2,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api'; const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; -// Example address to query (Polkadot Hub address) +// Example address to query const ADDRESS = 'INSERT_ADDRESS'; async function main() { @@ -12,7 +12,7 @@ async function main() { // Initialize the API const api = await ApiPromise.create({ provider: wsProvider }); - console.log('Connected to Polkadot Hub'); + console.log('Connected to Polkadot Hub TestNet'); console.log(`Querying runtime APIs for: ${ADDRESS}\n`); // Call AccountNonceApi to get the account nonce diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html index fd8bdf448..148ac81de 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime-apis-py.html @@ -1,14 +1,14 @@
python runtime_apis.py - Connected to Polkadot Hub + Connected to Polkadot Hub TestNet Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 AccountNonceApi Results: Account Nonce: 11 Core API Results: - Spec Name: statemint - Spec Version: 2000003 + Spec Name: asset-hub-paseo + Spec Version: 1004001 Impl Version: 0
diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py index 28b718ffa..7e183bff4 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py @@ -2,15 +2,15 @@ ASSET_HUB_RPC = "INSERT_WS_ENDPOINT" -# Example address to query (Polkadot Hub address) +# Example address to query ADDRESS = "INSERT_ADDRESS" def main(): - # Connect to Polkadot Hub + # Connect to Polkadot Hub TestNet (Paseo Asset Hub) substrate = SubstrateInterface(url=ASSET_HUB_RPC) - print("Connected to Polkadot Hub") + print("Connected to Polkadot Hub TestNet") print(f"Querying runtime APIs for: {ADDRESS}\n") # Call AccountNonceApi to get the account nonce diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html index caa76b686..31b4f4a42 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/runtime-apis-rs.html @@ -1,7 +1,7 @@
cargo run --bin runtime_apis - Connected to Polkadot Hub + Connected to Polkadot Hub TestNet Querying runtime APIs for: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 AccountNonceApi Results: diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs index aaf2f2916..17b03250a 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs @@ -9,7 +9,7 @@ pub mod asset_hub {} const ASSET_HUB_RPC: &str = "INSERT_WS_ENDPOINT"; -// Example address to query (Polkadot Hub address) +// Example address to query const ADDRESS: &str = "INSERT_ADDRESS"; #[tokio::main(flavor = "current_thread")] @@ -17,7 +17,7 @@ async fn main() -> Result<(), Box> { // Initialize the Subxt client let api = OnlineClient::::from_url(ASSET_HUB_RPC).await?; - println!("Connected to Polkadot Hub"); + println!("Connected to Polkadot Hub TestNet"); println!("Querying runtime APIs for: {}\n", ADDRESS); // Parse the address From b889d99933f60f7432b96070270d5785b6bf297d Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Mon, 15 Dec 2025 14:00:34 +0700 Subject: [PATCH 3/9] Update .chain-interactions/query-data/runtime-api-calls.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com> --- .chain-interactions/query-data/runtime-api-calls.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chain-interactions/query-data/runtime-api-calls.md b/.chain-interactions/query-data/runtime-api-calls.md index 37ca386f3..2f3141ad9 100644 --- a/.chain-interactions/query-data/runtime-api-calls.md +++ b/.chain-interactions/query-data/runtime-api-calls.md @@ -26,7 +26,7 @@ This guide demonstrates how to call runtime APIs using five popular SDKs: - **[Python Substrate Interface](/reference/tools/py-substrate-interface/){target=\_blank}** - Python library for Substrate chains - **[Subxt](/reference/tools/subxt/){target=\_blank}** - Rust library with compile-time type safety -Select your preferred SDK below to see complete, runnable examples that query Polkadot Hub TestNet (Paseo Asset Hub) for account nonces and metadata information. +Select your preferred SDK below to see complete, runnable examples that query Polkadot Hub TestNet for account nonces and metadata information. ## Call Runtime APIs From 3c6c19c2497a646a6dc6263aa26ed639e9e36424 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Mon, 15 Dec 2025 14:00:50 +0700 Subject: [PATCH 4/9] Update .snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com> --- .../query-data/runtime-api-calls/psi/runtime_apis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py index 7e183bff4..aff907955 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py @@ -7,7 +7,7 @@ def main(): - # Connect to Polkadot Hub TestNet (Paseo Asset Hub) + # Connect to Polkadot Hub TestNet substrate = SubstrateInterface(url=ASSET_HUB_RPC) print("Connected to Polkadot Hub TestNet") From 6f31a6341b4c1fe2b834e9cbf9b5c362dc816886 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Mon, 15 Dec 2025 14:01:07 +0700 Subject: [PATCH 5/9] Update .chain-interactions/query-data/runtime-api-calls.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com> --- .chain-interactions/query-data/runtime-api-calls.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chain-interactions/query-data/runtime-api-calls.md b/.chain-interactions/query-data/runtime-api-calls.md index 2f3141ad9..79dc59af6 100644 --- a/.chain-interactions/query-data/runtime-api-calls.md +++ b/.chain-interactions/query-data/runtime-api-calls.md @@ -258,7 +258,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po subxt metadata --url INSERT_WS_ENDPOINT -o asset_hub_metadata.scale ``` - Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://asset-hub-paseo.dotters.network` for Polkadot Hub TestNet (Paseo Asset Hub). + Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://asset-hub-paseo.dotters.network` for Polkadot Hub TestNet. 4. Update `Cargo.toml` with the required dependencies: From 659dba6203585492b05fbcaae0fd2e599a2c2f28 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Mon, 15 Dec 2025 14:01:17 +0700 Subject: [PATCH 6/9] Update .snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com> --- .../query-data/runtime-api-calls/dedot/runtime-apis.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts index c19f4252c..d4ab6516f 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts @@ -7,7 +7,7 @@ const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; const ADDRESS = 'INSERT_ADDRESS'; async function main() { - // Initialize provider and client with Asset Hub types + // Initialize provider and client with Polkadot TestNet types const provider = new WsProvider(ASSET_HUB_RPC); const client = await DedotClient.new(provider); From 170a3031f1af2ebf9a59661f26be48d46c225f1e Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Mon, 15 Dec 2025 14:04:02 +0700 Subject: [PATCH 7/9] Rename ASSET_HUB_RPC to POLKADOT_TESTNET_RPC in all code snippets --- .../query-data/runtime-api-calls/dedot/runtime-apis.ts | 4 ++-- .../query-data/runtime-api-calls/papi/runtime-apis.ts | 4 ++-- .../query-data/runtime-api-calls/pjs/runtime-apis.js | 4 ++-- .../query-data/runtime-api-calls/psi/runtime_apis.py | 4 ++-- .../runtime-api-calls/subxt/src/bin/runtime_apis.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts index d4ab6516f..08519872d 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/dedot/runtime-apis.ts @@ -1,14 +1,14 @@ import { DedotClient, WsProvider } from 'dedot'; import type { PolkadotAssetHubApi } from '@dedot/chaintypes'; -const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; +const POLKADOT_TESTNET_RPC = 'INSERT_WS_ENDPOINT'; // Example address to query const ADDRESS = 'INSERT_ADDRESS'; async function main() { // Initialize provider and client with Polkadot TestNet types - const provider = new WsProvider(ASSET_HUB_RPC); + const provider = new WsProvider(POLKADOT_TESTNET_RPC); const client = await DedotClient.new(provider); console.log('Connected to Polkadot Hub TestNet'); diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts index 4b28d8b99..31d741fb2 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts @@ -3,7 +3,7 @@ import { getWsProvider } from 'polkadot-api/ws-provider/node'; import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat'; import { polkadotTestNet } from '@polkadot-api/descriptors'; -const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; +const POLKADOT_TESTNET_RPC = 'INSERT_WS_ENDPOINT'; // Example address to query const ADDRESS = 'INSERT_ADDRESS'; @@ -11,7 +11,7 @@ const ADDRESS = 'INSERT_ADDRESS'; async function main() { // Create the client connection const client = createClient( - withPolkadotSdkCompat(getWsProvider(ASSET_HUB_RPC)) + withPolkadotSdkCompat(getWsProvider(POLKADOT_TESTNET_RPC)) ); // Get the typed API for Polkadot Hub TestNet (Paseo Asset Hub) diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js index f7f33c38c..a59cd0578 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/pjs/runtime-apis.js @@ -1,13 +1,13 @@ import { ApiPromise, WsProvider } from '@polkadot/api'; -const ASSET_HUB_RPC = 'INSERT_WS_ENDPOINT'; +const POLKADOT_TESTNET_RPC = 'INSERT_WS_ENDPOINT'; // Example address to query const ADDRESS = 'INSERT_ADDRESS'; async function main() { // Create a WebSocket provider - const wsProvider = new WsProvider(ASSET_HUB_RPC); + const wsProvider = new WsProvider(POLKADOT_TESTNET_RPC); // Initialize the API const api = await ApiPromise.create({ provider: wsProvider }); diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py index aff907955..5ef58091b 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/psi/runtime_apis.py @@ -1,6 +1,6 @@ from substrateinterface import SubstrateInterface -ASSET_HUB_RPC = "INSERT_WS_ENDPOINT" +POLKADOT_TESTNET_RPC = "INSERT_WS_ENDPOINT" # Example address to query ADDRESS = "INSERT_ADDRESS" @@ -8,7 +8,7 @@ def main(): # Connect to Polkadot Hub TestNet - substrate = SubstrateInterface(url=ASSET_HUB_RPC) + substrate = SubstrateInterface(url=POLKADOT_TESTNET_RPC) print("Connected to Polkadot Hub TestNet") print(f"Querying runtime APIs for: {ADDRESS}\n") diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs index 17b03250a..6348cb324 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs @@ -7,7 +7,7 @@ use subxt::{OnlineClient, PolkadotConfig}; #[subxt::subxt(runtime_metadata_path = "asset_hub_metadata.scale")] pub mod asset_hub {} -const ASSET_HUB_RPC: &str = "INSERT_WS_ENDPOINT"; +const POLKADOT_TESTNET_RPC: &str = "INSERT_WS_ENDPOINT"; // Example address to query const ADDRESS: &str = "INSERT_ADDRESS"; @@ -15,7 +15,7 @@ const ADDRESS: &str = "INSERT_ADDRESS"; #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { // Initialize the Subxt client - let api = OnlineClient::::from_url(ASSET_HUB_RPC).await?; + let api = OnlineClient::::from_url(POLKADOT_TESTNET_RPC).await?; println!("Connected to Polkadot Hub TestNet"); println!("Querying runtime APIs for: {}\n", ADDRESS); From 08864605800189e270c908272f7131e961f5fcc6 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Mon, 15 Dec 2025 14:05:15 +0700 Subject: [PATCH 8/9] Rename Subxt metadata file to polkadot_testnet_metadata.scale --- .chain-interactions/query-data/runtime-api-calls.md | 2 +- .../runtime-api-calls/subxt/src/bin/runtime_apis.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.chain-interactions/query-data/runtime-api-calls.md b/.chain-interactions/query-data/runtime-api-calls.md index 79dc59af6..9df75f452 100644 --- a/.chain-interactions/query-data/runtime-api-calls.md +++ b/.chain-interactions/query-data/runtime-api-calls.md @@ -255,7 +255,7 @@ Select your preferred SDK below to see complete, runnable examples that query Po 3. Download the Polkadot Hub TestNet metadata: ```bash - subxt metadata --url INSERT_WS_ENDPOINT -o asset_hub_metadata.scale + subxt metadata --url INSERT_WS_ENDPOINT -o polkadot_testnet_metadata.scale ``` Ensure to replace `INSERT_WS_ENDPOINT` with the proper WebSocket endpoint, such as `wss://asset-hub-paseo.dotters.network` for Polkadot Hub TestNet. diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs index 6348cb324..7f08faf61 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/subxt/src/bin/runtime_apis.rs @@ -4,8 +4,8 @@ use subxt::utils::AccountId32; use subxt::{OnlineClient, PolkadotConfig}; // Generate an interface from the node's metadata -#[subxt::subxt(runtime_metadata_path = "asset_hub_metadata.scale")] -pub mod asset_hub {} +#[subxt::subxt(runtime_metadata_path = "polkadot_testnet_metadata.scale")] +pub mod polkadot_testnet {} const POLKADOT_TESTNET_RPC: &str = "INSERT_WS_ENDPOINT"; @@ -24,7 +24,7 @@ async fn main() -> Result<(), Box> { let account = AccountId32::from_str(ADDRESS)?; // Call AccountNonceApi using static interface - let nonce_call = asset_hub::apis() + let nonce_call = polkadot_testnet::apis() .account_nonce_api() .account_nonce(account.clone()); let nonce = api.runtime_api().at_latest().await?.call(nonce_call).await?; From 57d10b34fc6dc191880b2905e94bf0594f2d0283 Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Tue, 16 Dec 2025 12:59:24 +0700 Subject: [PATCH 9/9] Update .snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com> --- .../query-data/runtime-api-calls/papi/runtime-apis.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts index 31d741fb2..93a3e1630 100644 --- a/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts +++ b/.snippets/code/chain-interactions/query-data/runtime-api-calls/papi/runtime-apis.ts @@ -14,7 +14,7 @@ async function main() { withPolkadotSdkCompat(getWsProvider(POLKADOT_TESTNET_RPC)) ); - // Get the typed API for Polkadot Hub TestNet (Paseo Asset Hub) + // Get the typed API for Polkadot Hub TestNet const api = client.getTypedApi(polkadotTestNet); console.log('Connected to Polkadot Hub TestNet');