Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some basic usage docs to README. #319

Merged
merged 5 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,46 @@ 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 node.

1. Install:
```bash
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
a different node then the `metadata` command accepts a `--url` argument.

### Generating the runtime API from the downloaded metadata

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 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

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

Expand All @@ -25,11 +64,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

<sup>
Expand Down