Skip to content

Commit 45dbb69

Browse files
committed
Apply suggestions
1 parent 80ddade commit 45dbb69

File tree

2 files changed

+45
-49
lines changed

2 files changed

+45
-49
lines changed

develop/toolkit/api-libraries/subxt.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: Subxt
3-
description: TODO
2+
title: Subxt Rust API
3+
description: Subxt is a Rust library for type-safe interaction with Polkadot SDK blockchains, enabling transactions, state queries, runtime API access, and more.
44
---
55

6-
# Subxt
6+
# Subxt Rust API
77

88
## Introduction
99

10-
Subxt is a Rust library designed for interacting with Polkadot SDK-based blockchains. It provides a type-safe interface for submitting transactions, querying on-chain state, and performing other blockchain interactions. By leveraging Rust’s strong type system, Subxt ensures that your code is validated at compile time, reducing runtime errors and improving reliability.
10+
subxt is a Rust library designed for interacting with Polkadot SDK-based blockchains. It provides a type-safe interface for submitting transactions, querying on-chain state, and performing other blockchain interactions. By leveraging Rust’s strong type system, subxt ensures that your code is validated at compile time, reducing runtime errors and improving reliability.
1111

1212
## Prerequisites
1313

14-
Before using Subxt, ensure you have the following installed:
14+
Before using subxt, ensure you have the following installed:
1515

1616
- Rust and Cargo installed on your system. You can install them using [Rustup](https://rustup.rs/){target=\_blank}
1717
- A Rust project initialized. If you don’t have one, create it with:
@@ -23,7 +23,7 @@ Before using Subxt, ensure you have the following installed:
2323

2424
To use subxt in your project, you need to install the necessary dependencies. Each plays a specific role in enabling interaction with the blockchain:
2525

26-
### Install subxt-cli
26+
### Install the Subxt CLI
2727

2828
[`subxt-cli`](https://crates.io/crates/subxt-cli){target=\_blank} is a command-line tool that provides utilities for working with Polkadot SDK metadata. In the context of subxt, it is essential for downloading chain metadata, which is required to generate type-safe Rust interfaces for interacting with the blockchain. Install it using:
2929

@@ -47,7 +47,7 @@ These dependencies are essential for interacting with the blockchain:
4747
cargo add subxt-signer
4848
```
4949

50-
- **[tokio](https://crates.io/crates/tokio){target=\_blank}** - an asynchronous runtime for Rust. Since blockchain operations are async, Tokio enables efficient handling of network requests
50+
- **[tokio](https://crates.io/crates/tokio){target=\_blank}** - an asynchronous runtime for Rust. Since blockchain operations are async, Tokio enables efficient handling of network requests. The `rt` feature enables Tokio’s runtime, including the current-thread single-threaded scheduler, necessary for async execution. The `macros` feature provides procedural macros like `#[tokio::main]` to simplify runtime setup
5151

5252
```bash
5353
cargo add tokio --features rt,macros
@@ -61,7 +61,7 @@ After adding the dependencies, your `Cargo.toml` should look like this:
6161

6262
## Get Started
6363

64-
This guide will walk you through the basic operations using subxt.
64+
This guide will walk you through the fundamental operations of subxt, from setting up your environment to executing transactions and querying blockchain state.
6565

6666
### Downloading Chain Metadata
6767

@@ -81,18 +81,18 @@ Use the `#[subxt::subxt]` macro to generate a type-safe Rust interface from the
8181

8282
Once subxt interfaces are generated, you can interact with your node in the following ways:
8383

84-
- **Transactions** - builds and submits transactions, monitors their inclusion in blocks, and retrieves associated events
85-
- **Storage** - enables querying of node storage data
86-
- **Events** - retrieves events emitted from recent blocks
87-
- **Constants** - accesses constant values stored in nodes that remain unchanged across a specific runtime version.
88-
- **Blocks** - loads recent blocks or subscribes to new/finalized blocks, allowing examination of extrinsics, events, and storage at those blocks
89-
- **Runtime APIs** - makes calls into pallet runtime APIs to fetch data
90-
- **Custom values** - accesses "custom values" contained within metadata
91-
- **Raw RPC calls** - facilitates raw RPC requests to compatible nodes
84+
- **[Transactions](https://docs.rs/subxt/latest/subxt/book/usage/transactions/index.html){target=\_blank}** - builds and submits transactions, monitors their inclusion in blocks, and retrieves associated events
85+
- **[Storage](https://docs.rs/subxt/latest/subxt/book/usage/storage/index.html){target=\_blank}** - enables querying of node storage data
86+
- **[Events](https://docs.rs/subxt/latest/subxt/book/usage/events/index.html){target=\_blank}** - retrieves events emitted from recent blocks
87+
- **[Constants](https://docs.rs/subxt/latest/subxt/book/usage/constants/index.html){target=\_blank}** - accesses constant values stored in nodes that remain unchanged across a specific runtime version.
88+
- **[Blocks](https://docs.rs/subxt/latest/subxt/book/usage/blocks/index.html){target=\_blank}** - loads recent blocks or subscribes to new/finalized blocks, allowing examination of extrinsics, events, and storage at those blocks
89+
- **[Runtime APIs](https://docs.rs/subxt/latest/subxt/book/usage/runtime_apis/index.html){target=\_blank}** - makes calls into pallet runtime APIs to fetch data
90+
- **[Custom values](https://docs.rs/subxt/latest/subxt/book/usage/custom_values/index.html){target=\_blank}** - accesses "custom values" contained within metadata
91+
- **[Raw RPC calls](https://docs.rs/subxt/latest/subxt/book/usage/rpc/index.html){target=\_blank}** - facilitates raw RPC requests to compatible nodes
9292

9393
### Initializing the Subxt client
9494

95-
To interact with a blockchain node using Subxt, create an asynchronous main function and initialize the client. Replace `INSERT_NODE_URL` with the URL of your target node:
95+
To interact with a blockchain node using subxt, create an asynchronous main function and initialize the client. Replace `INSERT_NODE_URL` with the URL of your target node:
9696

9797
```rust
9898
--8<-- 'code/develop/toolkit/api-libraries/subxt/subxt.rs::17'
@@ -102,7 +102,7 @@ To interact with a blockchain node using Subxt, create an asynchronous main func
102102

103103
### Reading Chain Data
104104

105-
Subxt provides multiple ways to access on-chain data:
105+
subxt provides multiple ways to access on-chain data:
106106

107107
- Constants - constants are predefined values in the runtime that remain unchanged unless modified by a runtime upgrade
108108

@@ -114,22 +114,20 @@ Subxt provides multiple ways to access on-chain data:
114114

115115
- State - state refers to the current chain data, which updates with each block
116116

117-
To fetch account information, use:
117+
To fetch account information, replace `INSERT_ADDRESS` with the address you want to fetch data from and use:
118118

119119
```rust
120120
--8<-- 'code/develop/toolkit/api-libraries/subxt/subxt.rs:26:42'
121121
```
122122

123123
### Submitting Transasctions
124124

125-
To submit a transaction, you need to construct an extrinsic, sign it with your private key, and send it to the blockchain.
126-
127-
For example, to transfer funds to another account:
125+
To submit a transaction, you need to construct an extrinsic, sign it with your private key, and send it to the blockchain. Replace `INSERT_DEST_ADDRESS` with the recipient’s address, `INSERT_AMOUNT` with the amount to transfer, and `INSERT_SECRET_PHRASE` with the sender’s mnemonic phrase:
128126

129127
```rust
130128
--8<-- 'code/develop/toolkit/api-libraries/subxt/subxt.rs:44:72'
131129
```
132130

133131
## Where to Go Next
134132

135-
Now that you've covered the basics, dive into the official [Subxt documentation](https://docs.rs/subxt/latest/subxt/book/index.html){target=\_blank} for comprehensive reference materials and advanced features.
133+
Now that you've covered the basics, dive into the official [subxt documentation](https://docs.rs/subxt/latest/subxt/book/index.html){target=\_blank} for comprehensive reference materials and advanced features.

llms.txt

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7768,19 +7768,19 @@ To dive deeper, refer to the [official Sidecar documentation](https://github.com
77687768
Doc-Content: https://docs.polkadot.com/develop/toolkit/api-libraries/subxt/
77697769
--- BEGIN CONTENT ---
77707770
---
7771-
title: Subxt
7772-
description: TODO
7771+
title: Subxt Rust API
7772+
description: Subxt is a Rust library for type-safe interaction with Polkadot SDK blockchains, enabling transactions, state queries, runtime API access, and more.
77737773
---
77747774

7775-
# Subxt
7775+
# Subxt Rust API
77767776

77777777
## Introduction
77787778

7779-
Subxt is a Rust library designed for interacting with Polkadot SDK-based blockchains. It provides a type-safe interface for submitting transactions, querying on-chain state, and performing other blockchain interactions. By leveraging Rust’s strong type system, Subxt ensures that your code is validated at compile time, reducing runtime errors and improving reliability.
7779+
subxt is a Rust library designed for interacting with Polkadot SDK-based blockchains. It provides a type-safe interface for submitting transactions, querying on-chain state, and performing other blockchain interactions. By leveraging Rust’s strong type system, subxt ensures that your code is validated at compile time, reducing runtime errors and improving reliability.
77807780

77817781
## Prerequisites
77827782

7783-
Before using Subxt, ensure you have the following installed:
7783+
Before using subxt, ensure you have the following installed:
77847784

77857785
- Rust and Cargo installed on your system. You can install them using [Rustup](https://rustup.rs/){target=\_blank}
77867786
- A Rust project initialized. If you don’t have one, create it with:
@@ -7792,7 +7792,7 @@ Before using Subxt, ensure you have the following installed:
77927792

77937793
To use subxt in your project, you need to install the necessary dependencies. Each plays a specific role in enabling interaction with the blockchain:
77947794

7795-
### Install subxt-cli
7795+
### Install the Subxt CLI
77967796

77977797
[`subxt-cli`](https://crates.io/crates/subxt-cli){target=\_blank} is a command-line tool that provides utilities for working with Polkadot SDK metadata. In the context of subxt, it is essential for downloading chain metadata, which is required to generate type-safe Rust interfaces for interacting with the blockchain. Install it using:
77987798

@@ -7816,7 +7816,7 @@ These dependencies are essential for interacting with the blockchain:
78167816
cargo add subxt-signer
78177817
```
78187818

7819-
- **[tokio](https://crates.io/crates/tokio){target=\_blank}** - an asynchronous runtime for Rust. Since blockchain operations are async, Tokio enables efficient handling of network requests
7819+
- **[tokio](https://crates.io/crates/tokio){target=\_blank}** - an asynchronous runtime for Rust. Since blockchain operations are async, Tokio enables efficient handling of network requests. The `rt` feature enables Tokio’s runtime, including the current-thread single-threaded scheduler, necessary for async execution. The `macros` feature provides procedural macros like `#[tokio::main]` to simplify runtime setup
78207820

78217821
```bash
78227822
cargo add tokio --features rt,macros
@@ -7838,7 +7838,7 @@ tokio = { version = "1.43.0", features = ["rt", "macros"] }
78387838

78397839
## Get Started
78407840

7841-
This guide will walk you through the basic operations using subxt.
7841+
This guide will walk you through the fundamental operations of subxt, from setting up your environment to executing transactions and querying blockchain state.
78427842

78437843
### Downloading Chain Metadata
78447844

@@ -7859,18 +7859,18 @@ pub mod polkadot {}
78597859

78607860
Once subxt interfaces are generated, you can interact with your node in the following ways:
78617861

7862-
- **Transactions** - builds and submits transactions, monitors their inclusion in blocks, and retrieves associated events
7863-
- **Storage** - enables querying of node storage data
7864-
- **Events** - retrieves events emitted from recent blocks
7865-
- **Constants** - accesses constant values stored in nodes that remain unchanged across a specific runtime version.
7866-
- **Blocks** - loads recent blocks or subscribes to new/finalized blocks, allowing examination of extrinsics, events, and storage at those blocks
7867-
- **Runtime APIs** - makes calls into pallet runtime APIs to fetch data
7868-
- **Custom values** - accesses "custom values" contained within metadata
7869-
- **Raw RPC calls** - facilitates raw RPC requests to compatible nodes
7862+
- **[Transactions](https://docs.rs/subxt/latest/subxt/book/usage/transactions/index.html){target=\_blank}** - builds and submits transactions, monitors their inclusion in blocks, and retrieves associated events
7863+
- **[Storage](https://docs.rs/subxt/latest/subxt/book/usage/storage/index.html){target=\_blank}** - enables querying of node storage data
7864+
- **[Events](https://docs.rs/subxt/latest/subxt/book/usage/events/index.html){target=\_blank}** - retrieves events emitted from recent blocks
7865+
- **[Constants](https://docs.rs/subxt/latest/subxt/book/usage/constants/index.html){target=\_blank}** - accesses constant values stored in nodes that remain unchanged across a specific runtime version.
7866+
- **[Blocks](https://docs.rs/subxt/latest/subxt/book/usage/blocks/index.html){target=\_blank}** - loads recent blocks or subscribes to new/finalized blocks, allowing examination of extrinsics, events, and storage at those blocks
7867+
- **[Runtime APIs](https://docs.rs/subxt/latest/subxt/book/usage/runtime_apis/index.html){target=\_blank}** - makes calls into pallet runtime APIs to fetch data
7868+
- **[Custom values](https://docs.rs/subxt/latest/subxt/book/usage/custom_values/index.html){target=\_blank}** - accesses "custom values" contained within metadata
7869+
- **[Raw RPC calls](https://docs.rs/subxt/latest/subxt/book/usage/rpc/index.html){target=\_blank}** - facilitates raw RPC requests to compatible nodes
78707870

78717871
### Initializing the Subxt client
78727872

7873-
To interact with a blockchain node using Subxt, create an asynchronous main function and initialize the client. Replace `INSERT_NODE_URL` with the URL of your target node:
7873+
To interact with a blockchain node using subxt, create an asynchronous main function and initialize the client. Replace `INSERT_NODE_URL` with the URL of your target node:
78747874

78757875
```rust
78767876
use std::str::FromStr;
@@ -7890,10 +7890,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
78907890
// Initialize the Subxt client for interacting with the blockchain.
78917891
let api = OnlineClient::<PolkadotConfig>::from_url(NODE_URL).await?;
78927892

7893-
// A query to obtain some contant:
7893+
// A query to obtain some constant.
78947894
let constant_query = polkadot::constants().balances().existential_deposit();
78957895

7896-
// Obtain the value:
7896+
// Obtain the value.
78977897
let value = api.constants().at(&constant_query)?;
78987898

78997899
println!("Existential deposit: {:?}", value);
@@ -7955,7 +7955,7 @@ Ok(())
79557955

79567956
### Reading Chain Data
79577957

7958-
Subxt provides multiple ways to access on-chain data:
7958+
subxt provides multiple ways to access on-chain data:
79597959

79607960
- Constants - constants are predefined values in the runtime that remain unchanged unless modified by a runtime upgrade
79617961

@@ -7964,15 +7964,15 @@ Subxt provides multiple ways to access on-chain data:
79647964
```rust
79657965
let constant_query = polkadot::constants().balances().existential_deposit();
79667966

7967-
// Obtain the value:
7967+
// Obtain the value.
79687968
let value = api.constants().at(&constant_query)?;
79697969

79707970
println!("Existential deposit: {:?}", value);
79717971
```
79727972

79737973
- State - state refers to the current chain data, which updates with each block
79747974

7975-
To fetch account information, use:
7975+
To fetch account information, replace `INSERT_ADDRESS` with the address you want to fetch data from and use:
79767976

79777977
```rust
79787978
const ADDRESS: &str = "INSERT_ADDRESS";
@@ -7995,9 +7995,7 @@ Subxt provides multiple ways to access on-chain data:
79957995

79967996
### Submitting Transasctions
79977997

7998-
To submit a transaction, you need to construct an extrinsic, sign it with your private key, and send it to the blockchain.
7999-
8000-
For example, to transfer funds to another account:
7998+
To submit a transaction, you need to construct an extrinsic, sign it with your private key, and send it to the blockchain. Replace `INSERT_DEST_ADDRESS` with the recipient’s address, `INSERT_AMOUNT` with the amount to transfer, and `INSERT_SECRET_PHRASE` with the sender’s mnemonic phrase:
80017999

80028000
```rust
80038001
const DEST_ADDRESS: &str = "INSERT_DEST_ADDRESS";
@@ -8032,7 +8030,7 @@ const DEST_ADDRESS: &str = "INSERT_DEST_ADDRESS";
80328030

80338031
## Where to Go Next
80348032

8035-
Now that you've covered the basics, dive into the official [Subxt documentation](https://docs.rs/subxt/latest/subxt/book/index.html){target=\_blank} for comprehensive reference materials and advanced features.
8033+
Now that you've covered the basics, dive into the official [subxt documentation](https://docs.rs/subxt/latest/subxt/book/index.html){target=\_blank} for comprehensive reference materials and advanced features.
80368034
--- END CONTENT ---
80378035

80388036
Doc-Content: https://docs.polkadot.com/develop/toolkit/

0 commit comments

Comments
 (0)