1
1
# Python Substrate Interface
2
-
2
+
3
3
[ ![ Travis CI Build Status] ( https://api.travis-ci.org/polkascan/py-substrate-interface.svg?branch=master )] ( https://travis-ci.org/polkascan/py-substrate-interface )
4
- [ ![ Latest Version] ( https://img.shields.io/pypi/v/substrate-interface.svg )] ( https://pypi.org/project/substrate-interface/ )
4
+ [ ![ Latest Version] ( https://img.shields.io/pypi/v/substrate-interface.svg )] ( https://pypi.org/project/substrate-interface/ )
5
5
[ ![ Supported Python versions] ( https://img.shields.io/pypi/pyversions/substrate-interface.svg )] ( https://pypi.org/project/substrate-interface/ )
6
6
[ ![ License] ( https://img.shields.io/pypi/l/substrate-interface.svg )] ( https://github.com/polkascan/py-substrate-interface/blob/master/LICENSE )
7
7
8
8
Python Substrate Interface Library
9
9
10
10
## Description
11
11
This library specializes in interfacing with a Substrate node, providing additional convenience methods to deal with
12
- SCALE encoding/decoding (the default output and input format of the Substrate JSONRPC), metadata parsing, type registry
12
+ SCALE encoding/decoding (the default output and input format of the Substrate JSONRPC), metadata parsing, type registry
13
13
management and versioning of types.
14
14
15
15
## Documentation
@@ -33,11 +33,11 @@ substrate = SubstrateInterface(
33
33
type_registry_preset = ' kusama'
34
34
)
35
35
36
- substrate.get_chain_head()
36
+ substrate.get_chain_head()
37
37
```
38
38
Note on support for wss, this is still quite limited at the moment as connections are not reused yet. Until support is
39
39
improved it is prefered to use http endpoints (e.g. http://127.0.0.1:9933 )
40
-
40
+
41
41
### Get extrinsics for a certain block
42
42
43
43
``` python
@@ -74,8 +74,8 @@ for extrinsic in result['block']['extrinsics']:
74
74
75
75
76
76
### Make a storage call
77
- The modules and storage functions are provided in the metadata (see ` substrate.get_metadata_storage_functions() ` ),
78
- parameters will be automatically converted to SCALE-bytes (also including decoding of SS58 addresses).
77
+ The modules and storage functions are provided in the metadata (see ` substrate.get_metadata_storage_functions() ` ),
78
+ parameters will be automatically converted to SCALE-bytes (also including decoding of SS58 addresses).
79
79
80
80
``` python
81
81
balance_info = substrate.get_runtime_state(
@@ -107,6 +107,17 @@ if balance_info:
107
107
))
108
108
```
109
109
110
+ Or get all the key pairs of a map:
111
+
112
+ ``` python
113
+ # Get all the stash and controller bondings.
114
+ all_bonded_stash_ctrls = substrate.iterate_map(
115
+ module = ' Staking' ,
116
+ storage_function = ' Bonded' ,
117
+ block_hash = block_hash
118
+ )
119
+ ```
120
+
110
121
### Create and send signed extrinsics
111
122
112
123
The following code snippet illustrates how to create a call, wrap it in an signed extrinsic and send it to the network:
@@ -157,9 +168,9 @@ if keypair.verify("Test123", signature):
157
168
### Metadata and type versioning
158
169
159
170
Py-substrate-interface makes it also possible to easily interprete changed types and historic runtimes. As an example
160
- we create an (not very useful) historic call of a module that has been removed later on: retrieval of historic metadata and
161
- apply the correct version of types in the type registry is all done automatically. Because parsing of metadata and
162
- type registry is quite heavy, the result will be cached per runtime id. In the future there could be support for
171
+ we create an (not very useful) historic call of a module that has been removed later on: retrieval of historic metadata and
172
+ apply the correct version of types in the type registry is all done automatically. Because parsing of metadata and
173
+ type registry is quite heavy, the result will be cached per runtime id. In the future there could be support for
163
174
caching backends like Redis to make this cache more persistent.
164
175
165
176
Create an unsigned extrinsic of a module that was removed by providing block hash:
0 commit comments