Skip to main content

Library for interfacing with a Substrate node

Project description

Python Substrate Interface

Build Status Latest Version Supported Python versions License

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

substrate-interface-1.7.11.tar.gz (79.2 kB view details)

Uploaded Source

Built Distribution

substrate_interface-1.7.11-py3-none-any.whl (60.3 kB view details)

Uploaded Python 3

File details

Details for the file substrate-interface-1.7.11.tar.gz.

File metadata

  • Download URL: substrate-interface-1.7.11.tar.gz
  • Upload date:
  • Size: 79.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for substrate-interface-1.7.11.tar.gz
Algorithm Hash digest
SHA256 4caa5eacb9996edbe76ad12249521b3542bbd8d9d69b96734087201db1fef8f6
MD5 013155e93cf81e4d1d4fe4c7f2818de1
BLAKE2b-256 7a44825433c906bdb69ab66fd3967c11fcfbcd953241e9d6257fd6a21c4cdc76

See more details on using hashes here.

File details

Details for the file substrate_interface-1.7.11-py3-none-any.whl.

File metadata

File hashes

Hashes for substrate_interface-1.7.11-py3-none-any.whl
Algorithm Hash digest
SHA256 ce19bc97481769238ed23c752db985a3058637918693f2db6aeed2fab3756075
MD5 0f05e93903aa1e4ede308a069ee144eb
BLAKE2b-256 56e137344b7acd260cbfed13563dcbab391c7c4b0c9eca5ec59aba138c5dca9e

See more details on using hashes here.

Supported by

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