Skip to main content

A library for interacting with Substrate node (py-substrate-interface fork)

Project description

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 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

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

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiosubstrate-0.1.1.tar.gz (78.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiosubstrate-0.1.1-py3-none-any.whl (58.0 kB view details)

Uploaded Python 3

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

Hashes for aiosubstrate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 79fc16d6aafcfe4f04c15f72fe3b7e0d44af16e5c94aae3e5be475b58ec9211a
MD5 4721dda94762860b3e55a8cd4981b93b
BLAKE2b-256 44dc1dcec325def692e8056810220c093a9c41853f6a49ac0d3dab2a8ae552c1

See more details on using hashes here.

File details

Details for the file aiosubstrate-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiosubstrate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce4cfbb784340d8bcd9e3a23d059ae9143de5960f5304e074dad22aca1312d85
MD5 935d92b8c116d09104d9503fc3411cf6
BLAKE2b-256 20bb20708304f2d598cb6cbf33e4635913c9f922f174a1cf2bea8d4f48faa670

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page