The metadata of a given runtime is a critical piece of information as it describes how one can interact with the runtime, what operations are possible and what are the signatures of the calls. It contains the exhaustive list of all the features publicly exposed by the runtime.
Note
|
This tool only works with Substrate-based runtimes which are >=V11 . For earlier versions, you’ll need to connect to an archive node.
|
Any node can be queried to provide its current metadata. This can be displayed in json format for instance. This is a great way to have a peek at what the runtime can do. You may however want to inspect a runtime that was not deployed yet to any node.
subwasm
can work offline on wasm files without any node or internet connectivity.
subwasm
can:
-
get the metadata from a a wasm file directly (no need for a node): command
get
-
show summary information and version of a runtime: commands
info
andversion
) -
diff between two runtime to help users spot changes and difference: command
diff
-
show the list of pallets and their content (calls, events, errors, storage, constants): command
show
-
analyze 2 runtimes to figure out whether they are compatible and if the
transaction_version
needs to be bumped: commanddiff
-
compress and decompress a runtime WASM: commands
compress
anddecompress
-
get the latest metadata from a running node: command
get
-
fetch the latest runtime (wasm) from a running node: command
get
-
get runtime and metadata at any point of time using a Block hash as reference: command
get
-
do all of the above with an output for human or as json
cargo install --locked --git https://github.com/chevdor/subwasm --tag v0.16.1
MacOS Homebrew users can use:
brew tap chevdor/subwasm https://github.com/chevdor/subwasm brew install subwasm
We will start by fetching the runtime from a node.
Note
|
Please note that you will likely need to connect to an archive node to retrieve an older runtime (<V11 ). A runtime takes around 2MB of storage on-chain and thus, older versions are pruned and will no longer be accessible if you are connecting to a non-archive node.
|
subwasm get subwasm get http://localhost:9933 subwasm get http://localhost:9933 --output runtime_000.wasm
subwasm get brew tap chevdor/subwasm --block 0x4d6a0bca208b85d41833a7f35cf73d1ae6974f4bad8ab576e2c3f751d691fe6c
Note
|
By default, your runtime will be saved as runtime_000.wasm . Running this command again will increase the counter so we you don’t lose your previous runtime. You may also use the --output flag to provide the destination and filename of your choice. Beware, in this case, there will be no incremented counter.
|
# Show the runtime version and exit with status 0 subwasm info kusama-2030.wasm # Provide a few explanations and exit with a status that is not 0 subwasm info tictactoe.wasm
Tip
|
jq can be used to reprocess the json output. For instance, removing all the documentation from the metadata makes it significantly smaller. The example below shows how to remove documentation , value and default making it much easier on the eyes for human parsing…
|
subwasm --json meta runtime.wasm | jq 'del( .. | .documentation?, .default?, .value? )'
Here is a list of other projects allowing to get the raw metadata through a rpc call:
-
PolkadotJS from Jaco / Parity
-
subsee from Andrew / Parity
-
substrate-api-client from SCS
-
subxt from Parity
All those alternatives require a running node and access it via jsonrpc.