|
Download substrate_interface/docs/usage/call-runtime-apis.md from Dorothydu/gitrepo_top_sample_50: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/substrate_interface/docs/usage/call-runtime-apis.md
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_top_sample_50/substrate_interface/docs/usage/call-runtime-apis.md
-
curl -L -o call-runtime-apis.md https://huggingface.co/datasets/Dorothydu/gitrepo_top_sample_50/resolve/main/substrate_interface/docs/usage/call-runtime-apis.md
1.28 kB
Call runtime APIs
Each Substrate node contains a runtime. The runtime contains the business logic of the chain. It defines what transactions are valid and invalid and determines how the chain's state changes in response to transactions.
A Runtime API facilitates this kind of communication between the outer node and the runtime. More information about Runtime APIs
Example
result = substrate.runtime_call("AccountNonceApi", "account_nonce", ["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"])
# <U32(value=2)>
List of available runtime APIs and methods
runtime_calls = substrate.get_metadata_runtime_call_functions()
#[
# <RuntimeCallDefinition(value={'description': 'The API to query account nonce (aka transaction index)', 'params': [{'name': 'account_id', 'type': 'AccountId'}], 'type': 'Index', 'api': 'AccountNonceApi', 'method': 'account_nonce'})>
# ...
#]
Get param type decomposition
A helper function to compose the parameters for this runtime API call
runtime_call = substrate.get_metadata_runtime_call_function("ContractsApi", "call")
param_info = runtime_call.get_param_info()
# ['AccountId', 'AccountId', 'u128', 'u64', (None, 'u128'), 'Bytes']