From 076c3f652b75f7ab924ce551efcd77733df6824c Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 12 Nov 2021 11:25:23 +0000 Subject: [PATCH 1/5] Add some basic usage docs to README. --- README.md | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c331d1de90..de8d8d3629 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,41 @@ A library to **sub**mit e**xt**rinsics to a [substrate](https://github.com/parit ## Usage -See [examples](./examples). +### Downloading metadata from a Substrate node + +Use the `subxt-cli` CLI tool to download the metadata for your target runtime from a Substrate node. + +```bash +cargo run -p subxt-cli -- metadata -f bytes > metadata.scale +``` + +This defaults to querying the metadata of a locally running node on the default `http://localhost:9933/`. If querying +a different node then the `metadata` command accepts a `--url` argument. + +### Generating the runtime API from the downloaded metadata + +Simply declare a module and decorate it with the `subxt` attribute which points at the downloaded metadata for the +target runtime: + +```rust +#[subxt::subxt(runtime_metadata_path = "metadata.scale")] +pub mod node_runtime { } +``` + +**Important:** `runtime_metadata_path` resolves to a path relative to the directory where your project's `Cargo.toml` +resides, *not* relative to the source file. + +### Initializing the API client + +API is still a work in progress. See [examples](./examples) for the current usage. + +### Querying Storage + +API is still a work in progress. See [tests](./tests/integration/frame) for the current usage. + +### Submitting Extrinsics + +API is still a work in progress. See [examples](./examples/polkadot_balance_transfer.rs) for the current usage. ## Integration Testing @@ -25,11 +59,6 @@ cargo install --git https://github.com/paritytech/substrate node-cli --tag=polka [substrate-api-client](https://github.com/scs/substrate-api-client) provides similar functionality. -## Subxt Client -By default the client builder will connect to a full node via rpc. The `subxt-client` helps -embedding a light client directly. It can also be used to embed a full node. This is especially -useful for testing and ci. - #### License From 329a8bdbff9fb830acdd155e8f3d065a18d24f52 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 12 Nov 2021 11:44:34 +0000 Subject: [PATCH 2/5] Update README.md Co-authored-by: David --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index de8d8d3629..5562a3f7b6 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A library to **sub**mit e**xt**rinsics to a [substrate](https://github.com/parit ### Downloading metadata from a Substrate node -Use the `subxt-cli` CLI tool to download the metadata for your target runtime from a Substrate node. +Use the `subxt-cli` CLI tool to download the metadata for your target runtime from a node. ```bash cargo run -p subxt-cli -- metadata -f bytes > metadata.scale From 32527279232864bec01476d896ceedae39d6880a Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 12 Nov 2021 11:47:01 +0000 Subject: [PATCH 3/5] Update README.md Co-authored-by: David --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5562a3f7b6..e772383915 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ a different node then the `metadata` command accepts a `--url` argument. ### Generating the runtime API from the downloaded metadata -Simply declare a module and decorate it with the `subxt` attribute which points at the downloaded metadata for the +Declare a module and decorate it with the `subxt` attribute which points at the downloaded metadata for the target runtime: ```rust From 4b3c50333fd0a48bcabcb9245a89cda7e37d4808 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 15 Nov 2021 09:37:35 +0000 Subject: [PATCH 4/5] Update README to specify subxt-cli usage --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e772383915..8cbc573bb5 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,15 @@ A library to **sub**mit e**xt**rinsics to a [substrate](https://github.com/parit ### Downloading metadata from a Substrate node -Use the `subxt-cli` CLI tool to download the metadata for your target runtime from a node. +Use the [`subxt-cli`](./cli) tool to download the metadata for your target runtime from a node. +1. Install: ```bash -cargo run -p subxt-cli -- metadata -f bytes > metadata.scale +cargo install subxt-cli +``` +2. Save the encoded metadata to a file: +```bash +subxt metadata -f bytes > metadata.scale ``` This defaults to querying the metadata of a locally running node on the default `http://localhost:9933/`. If querying From 9f31f6e13a7b4332632d8044b60a548c4e770fbc Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Mon, 15 Nov 2021 09:40:30 +0000 Subject: [PATCH 5/5] Clarify CARGO_MANIFEST_DIR path --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8cbc573bb5..5d681c8c37 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ target runtime: pub mod node_runtime { } ``` -**Important:** `runtime_metadata_path` resolves to a path relative to the directory where your project's `Cargo.toml` -resides, *not* relative to the source file. +**Important:** `runtime_metadata_path` resolves to a path relative to the directory where your crate's `Cargo.toml` +resides ([`CARGO_MANIFEST_DIR`](https://doc.rust-lang.org/cargo/reference/environment-variables.html)), *not* relative to the source file. ### Initializing the API client