async-substrate-interface

1.6.4 · active · verified Wed Apr 15

Asyncio library for interacting with Substrate. It aims to be mostly API-compatible with `py-substrate-interface`. The current version is 1.6.4, with frequent releases, often several per month. It utilizes `bt-decode` for faster SCALE decoding.

Warnings

Install

Imports

Quickstart

Initializes an `AsyncSubstrateInterface` to connect to a Substrate node (e.g., Polkadot) and performs an asynchronous query for an account's system data. Ensure an `asyncio` event loop is running to execute the main function.

import asyncio
from async_substrate_interface import AsyncSubstrateInterface

async def main():
    substrate = AsyncSubstrateInterface(
        url="wss://rpc.polkadot.io"
    )
    async with substrate:
        result = await substrate.query(
            module='System',
            storage_function='Account',
            params=['5CZs3T15Ky4jch1sUpSFwkUbYEnsCfe1WCY51fH3SPV6NFnf'] # Example address
        )
        print(result)

if __name__ == '__main__':
    asyncio.run(main())

view raw JSON →