Skip to content

dipdup-io/aiosubstrate

Repository files navigation

aiosubstrate

Twitter Monthly downloads GitHub stars Python Version License: Apache
Latest stable release Latest pre-release GitHub issues GitHub pull requests

⚠️ This project is not related to the PolkaScan team! 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-substrate-interface 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

TBD.

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 team! Please, do not send them aiosubstrate bug reports!

For questions, please see the Substrate StackExchange, upstream GitHub Discussions.

License

Apache 2.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published