Library for interfacing with a Substrate node
Project description
Python Substrate Interface
Description
This library specializes in interfacing with a Substrate node; querying storage, composing extrinsics, SCALE encoding/decoding and providing additional convenience methods to deal with the features and metadata of the Substrate runtime.
Documentation
Installation
pip install substrate-interface
Initialization
substrate = SubstrateInterface(url="ws://127.0.0.1:9944")
After connecting certain properties like ss58_format
will be determined automatically by querying the RPC node. At
the moment this will work for most MetadataV14
and above runtimes like Polkadot, Kusama, Acala, Moonbeam. For
older or runtimes under development the ss58_format
(default 42) and other properties should be set manually.
Quick usage
Balance information of an account
result = substrate.query('System', 'Account', ['F4xQKRUagnSGjFqafyhajLs94e7Vvzvr8ebwYJceKpr8R7T'])
print(result.value['data']['free']) # 635278638077956496
Create balance transfer extrinsic
call = substrate.compose_call(
call_module='Balances',
call_function='transfer',
call_params={
'dest': '5E9oDs9PjpsBbxXxRE9uMaZZhnBAV38n2ouLB28oecBDdeQo',
'value': 1 * 10**12
}
)
keypair = Keypair.create_from_uri('//Alice')
extrinsic = substrate.create_signed_extrinsic(call=call, keypair=keypair)
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
print(f"Extrinsic '{receipt.extrinsic_hash}' sent and included in block '{receipt.block_hash}'")
Contact and Support
For questions, please see the Substrate StackExchange, Github Discussions or reach out to us on our matrix chat group: Polkascan Technical.
License
https://github.com/polkascan/py-substrate-interface/blob/master/LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for substrate-interface-1.5.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 015d55344f46b6c8feefd270a7fa99fe17c4bb4c4e97705a8614d8172e472689 |
|
MD5 | 4bccb2cc618955056d5ba746fc22022f |
|
BLAKE2b-256 | 223ad2b3801e1578110417511b7af6bbad9aba83b3c2275e15696b733fd8cc8b |
Hashes for substrate_interface-1.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d652994ffb74a2d7c4a58701b6e1bdc51c1ea5ce1cc8dfe0782356b53e24ed40 |
|
MD5 | 58237e68eafcd6dee1786f3454ec2b80 |
|
BLAKE2b-256 | 7daeae60d000b9d0a133b758ffd7213a57964ed964a3c525c2824f5dfd237829 |