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
Using embedded light client
substrate = SubstrateInterface(chainspec="polkadot_asset_hub", relay_chainspecs=["polkadot"])
Using node RPC endpoint
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 or Github Discussions.
License
https://github.com/JAMdotTech/py-polkadot-sdk/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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file substrate_interface-1.8.1.tar.gz.
File metadata
- Download URL: substrate_interface-1.8.1.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
821be590fa4f3d9bc731b4c370341b57cd98ef3419c81289cd369bdeefc008de
|
|
| MD5 |
00c21ba68279766ee417c84ba222c5b0
|
|
| BLAKE2b-256 |
c53fe1483635a892b84727187cf8ba8477a20e4036361202650a0bdb93eacf8b
|
File details
Details for the file substrate_interface-1.8.1-py3-none-any.whl.
File metadata
- Download URL: substrate_interface-1.8.1-py3-none-any.whl
- Upload date:
- Size: 1.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07737b0dc86fb8962ec09c3518577556534f9ffa58ef1164fc70ffe8a5c54837
|
|
| MD5 |
20a9de1928c812197537b472af5943b5
|
|
| BLAKE2b-256 |
c72ed6e2bb34473bfc8b6e915a21ee1a5dbf67c57dff8abea407e4e46cee5d83
|