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.5.tar.gz (79.9 kB view details)

Uploaded Source

Built Distribution

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

substrate_interface-1.7.5-py3-none-any.whl (59.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for substrate-interface-1.7.5.tar.gz
Algorithm Hash digest
SHA256 8d4f961cd566d748f4a3ae0747983be5fe57e349071c0650114afc8c5ab06b93
MD5 7da6246653c851f879f824117ca138b6
BLAKE2b-256 29ea2d3b9c203c74c3dee1a8c88a5d576a9be8a7fc2c4a3f858dc7939006d719

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for substrate_interface-1.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8e8381b6ce6f370b90a6ae537964f118421f199663c9efd5b2a1b04982082005
MD5 bedcaef0eec63cf267472b74520af2c4
BLAKE2b-256 749b1dbbe65538d89c6b05a127774a677399a94e0c679d625a8b0d6b06521cb5

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