v0.36.0
[0.36.0] - 2024-05-16
This release adds a few new features, which I'll go over below in more detail.
subxt-core
We now have a brand new subxt-core
crate, which is #[no-std]
compatible, and contains a lot of the core logic that is needed in Subxt. Using this crate, you can do things in a no-std environment like:
blocks
: decode and explore block bodies.constants
: access and validate the constant addresses in some metadata.custom_values
: access and validate the custom value addresses in some metadata.metadata
: decode bytes into the metadata used throughout this library.storage
: construct storage request payloads and decode the results you'd get back.tx
: construct and sign transactions (extrinsics).runtime_api
: construct runtime API request payloads and decode the results you'd get back.events
: decode and explore events.
Check out the docs for more, including examples of each case.
A breaking change that comes from migrating a bunch of logic to this new crate is that the ExtrinsicParams
trait is now handed &ClientState<T>
rather than a Client
. ClientState
is just a concrete struct containing the state that one needs for things like signed extensions.
Support for reconnecting
We've baked in a bunch of support for automatically reconnecting after a connection loss into Subxt. This comes in three parts:
- An RPC client that is capable of reconnecting. This is gated behind the
unstable-reconnecting-rpc-client
feature flag at the moment, and - Handling in the subxt Backends such that when the RPC client notifies it that it is reconnecting, the backend will transparently handle this behind the scenes, or else pass on a
DisconnectedWillReconnect
error to the user where it cannot. Note that the individualLegacyRpcMethods
andUnstableRpcMethods
are not automatically retried on reconnection. Which leads us to.. - A couple of util helpers (
subxt::backend::retry
andsubxt::backend::retry_stream
) which can be used in conjunction with a reconnecting RPC client to make it easy to automatically retry RPC method calls where needed.
We'd love feedback on this reconnecting work! To try it out, enable the unstable-reconnecting-rpc-client
feature flag and then you can make use of this like so:
use std::time::Duration;
use futures::StreamExt;
use subxt::backend::rpc::reconnecting_rpc_client::{Client, ExponentialBackoff};
use subxt::{OnlineClient, PolkadotConfig};
// Generate an interface that we can use from the node's metadata.
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new client with with a reconnecting RPC client.
let rpc = Client::builder()
// We can configure the retry policy; here to an exponential backoff.
// This API accepts an iterator of retry delays, and here we use `take`
// to limit the number of retries.
.retry_policy(
ExponentialBackoff::from_millis(100)
.max_delay(Duration::from_secs(10))
.take(3),
)
.build("ws://localhost:9944".to_string())
.await?;
// Use this reconnecting client when instantiating a Subxt client:
let api: OnlineClient<PolkadotConfig> = OnlineClient::from_rpc_client(rpc.clone()).await?;
Check out the full example here.
Better Ethereum support
We've added built-in support for Ethereum style chains (eg Frontier and Moonbeam) in subxt-signer
, making it easier to sign transactions for these chains now.
Check out a full example here.
We plan to improve on this in the future, baking in better Ethereum support if possible so that it's as seamless to use AccountId20
as it is AccountId32
.
Stabilizing the new V2 RPCs (#1540, #1539, #1538)
A bunch of the new RPCs are now stable in the spec, and have consequently been stabilized here, bringing the unstable-backend
a step closer to being stabilized itself! We'll probably first remove the feature flag and next make it the default backend, in upcoming releases.
All of the notable changes in this release are as follows:
Added
- Add
frontier/ethereum
example (#1557) - Rpc: add full support reconnecting rpc client (#1505)
- Signer: ethereum implementation (#1501)
subxt-core
crate (#1466)
Changed
- Bump scale-decode and related deps to latest (#1583)
- Update Artifacts (auto-generated) (#1577)
- Update deps to use
scale-type-resolver
0.2 (#1565) - Stabilize transactionBroadcast methods (#1540)
- Stabilize transactionWatch methods (#1539)
- Stabilize chainHead methods (#1538)
- Rename traits to remove T suffix (#1535)
- Add Debug/Clone/etc for common Configs for convenience (#1542)
- Unstable_rpc: Add transactionBroadcast and transactionStop (#1497)
Fixed
- metadata: Fix cargo clippy (#1574)
- Fixed import in
subxt-signer::eth
(#1553) - chore: fix typos and link broken (#1541)
- Make subxt-core ready for publishing (#1508)
- Remove dupe storage item if we get one back, to be compatible with Smoldot + legacy RPCs (#1534)
- fix: substrate runner libp2p port (#1533)
- Swap BinaryHeap for Vec to avoid Ord constraint issue (#1523)
- storage_type: Strip key proper hash and entry bytes (32 instead of 16) (#1522)
- testing: Prepare light client testing with substrate binary and add subxt-test macro (#1507)