You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: develop/toolkit/api-libraries/subxt.md
+21-23Lines changed: 21 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
---
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.
4
4
---
5
5
6
-
# Subxt
6
+
# Subxt Rust API
7
7
8
8
## Introduction
9
9
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.
11
11
12
12
## Prerequisites
13
13
14
-
Before using Subxt, ensure you have the following installed:
14
+
Before using subxt, ensure you have the following installed:
15
15
16
16
- Rust and Cargo installed on your system. You can install them using [Rustup](https://rustup.rs/){target=\_blank}
17
17
- 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:
23
23
24
24
To use subxt in your project, you need to install the necessary dependencies. Each plays a specific role in enabling interaction with the blockchain:
25
25
26
-
### Install subxt-cli
26
+
### Install the Subxt CLI
27
27
28
28
[`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:
29
29
@@ -47,7 +47,7 @@ These dependencies are essential for interacting with the blockchain:
47
47
cargo add subxt-signer
48
48
```
49
49
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
51
51
52
52
```bash
53
53
cargo add tokio --features rt,macros
@@ -61,7 +61,7 @@ After adding the dependencies, your `Cargo.toml` should look like this:
61
61
62
62
## Get Started
63
63
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.
65
65
66
66
### Downloading Chain Metadata
67
67
@@ -81,18 +81,18 @@ Use the `#[subxt::subxt]` macro to generate a type-safe Rust interface from the
81
81
82
82
Once subxt interfaces are generated, you can interact with your node in the following ways:
83
83
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
92
92
93
93
### Initializing the Subxt client
94
94
95
-
To interact with a blockchain node using Subxt, create an asynchronous main functionand 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 functionand initialize the client. Replace `INSERT_NODE_URL` with the URL of your target node:
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:
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.
description: Subxt is a Rust library for type-safe interaction with Polkadot SDK blockchains, enabling transactions, state queries, runtime API access, and more.
7773
7773
---
7774
7774
7775
-
# Subxt
7775
+
# Subxt Rust API
7776
7776
7777
7777
## Introduction
7778
7778
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.
7780
7780
7781
7781
## Prerequisites
7782
7782
7783
-
Before using Subxt, ensure you have the following installed:
7783
+
Before using subxt, ensure you have the following installed:
7784
7784
7785
7785
- Rust and Cargo installed on your system. You can install them using [Rustup](https://rustup.rs/){target=\_blank}
7786
7786
- 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:
7792
7792
7793
7793
To use subxt in your project, you need to install the necessary dependencies. Each plays a specific role in enabling interaction with the blockchain:
7794
7794
7795
-
### Install subxt-cli
7795
+
### Install the Subxt CLI
7796
7796
7797
7797
[`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:
7798
7798
@@ -7816,7 +7816,7 @@ These dependencies are essential for interacting with the blockchain:
7816
7816
cargo add subxt-signer
7817
7817
```
7818
7818
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
7820
7820
7821
7821
```bash
7822
7822
cargo add tokio --features rt,macros
@@ -7838,7 +7838,7 @@ tokio = { version = "1.43.0", features = ["rt", "macros"] }
7838
7838
7839
7839
## Get Started
7840
7840
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.
7842
7842
7843
7843
### Downloading Chain Metadata
7844
7844
@@ -7859,18 +7859,18 @@ pub mod polkadot {}
7859
7859
7860
7860
Once subxt interfaces are generated, you can interact with your node in the following ways:
7861
7861
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
7870
7870
7871
7871
### Initializing the Subxt client
7872
7872
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:
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:
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.
0 commit comments