A library for interacting with Substrate node (py-substrate-interface fork)
Project description
aiosubstrate
⚠️ This project is not related to the PolkaScan or JAMdotTech teams! Please, do not send them aiosubstrate bug reports!
⚠️ This project is currently in the beta stage. Use with caution.
A library for interacting with Substrate node, an unofficial fork of py-polkadot-sdk (previously known py-substrate-interface) as with primary goal to achieve compatibility with Python asyncio.
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
- Upstream: Library documentation
- Upstream: Metadata documentation for Polkadot and Kusama ecosystem runtimes
Installation
pip install aiosubstrate
# with additional crypto libraries
pip install aiosubstrate[full]
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 = await substrate.query('System', 'Account', ['F4xQKRUagnSGjFqafyhajLs94e7Vvzvr8ebwYJceKpr8R7T'])
print(result.value['data']['free']) # 635278638077956496
Create balance transfer extrinsic
call = await substrate.compose_call(
call_module='Balances',
call_function='transfer',
call_params={
'dest': '5E9oDs9PjpsBbxXxRE9uMaZZhnBAV38n2ouLB28oecBDdeQo',
'value': 1 * 10**12
}
)
keypair = Keypair.create_from_uri('//Alice')
extrinsic = await substrate.create_signed_extrinsic(call=call, keypair=keypair)
receipt = await 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
⚠️ This project is not related to the PolkaScan or JAMdotTech teams! Please, do not send them aiosubstrate bug reports!
For questions, please see the Substrate StackExchange or Github Discussions.
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 aiosubstrate-0.1.1.tar.gz.
File metadata
- Download URL: aiosubstrate-0.1.1.tar.gz
- Upload date:
- Size: 78.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79fc16d6aafcfe4f04c15f72fe3b7e0d44af16e5c94aae3e5be475b58ec9211a
|
|
| MD5 |
4721dda94762860b3e55a8cd4981b93b
|
|
| BLAKE2b-256 |
44dc1dcec325def692e8056810220c093a9c41853f6a49ac0d3dab2a8ae552c1
|
File details
Details for the file aiosubstrate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: aiosubstrate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 58.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce4cfbb784340d8bcd9e3a23d059ae9143de5960f5304e074dad22aca1312d85
|
|
| MD5 |
935d92b8c116d09104d9503fc3411cf6
|
|
| BLAKE2b-256 |
20bb20708304f2d598cb6cbf33e4635913c9f922f174a1cf2bea8d4f48faa670
|