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.
pip install async-substrate-interfaceVerified import paths — ran on the pinned version, not inferred.
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.
Review the `v1.6.4` changelog and your Substrate node's API documentation for specifics on updated runtime API interactions. Adjust your code to use the modern API.
Upgrade your Python environment to version 3.10, 3.11, 3.12, 3.13, or 3.14. The library currently requires Python `<3.15,>=3.10`.
When migrating from `py-substrate-interface` or developing, carefully review the `async-substrate-interface` documentation and test critical paths to identify any API deviations or behavioral changes.
Be aware of these caching behaviors. Ensure environment variables are set correctly if you wish to override defaults. If using `DiskCachedAsyncSubstrateInterface` with multiple networks, remember that caches are separate per URI, which is usually desired but important to understand.
If your application is part of the Bittensor ecosystem, consider leveraging `AsyncSubtensor` for a more integrated and potentially optimized experience. If using `AsyncSubstrateInterface` directly, be mindful of any Bittensor-specific conventions or helper methods you might be missing.
Ensure the package is correctly installed using pip: `pip install async-substrate-interface`. Also, verify the import statement is `from async_substrate_interface import AsyncSubstrateInterface`.
Always `await` calls to asynchronous methods and initialize `AsyncSubstrateInterface` within an `async with` block inside an `async def` function.
```python
import asyncio
from async_substrate_interface import AsyncSubstrateInterface
async def main():
async with AsyncSubstrateInterface(url="wss://rpc.polkadot.io") as substrate:
result = await substrate.query(
module='System',
storage_function='Account',
params=['5CZs3T15Ky4jch1sUpSFwkUbYEnsCfe1WCY51fH3SPV6NFnf']
)
print(result)
if __name__ == '__main__':
asyncio.run(main())
```Verify the Substrate node is running and accessible at the specified URL. If connecting to a remote node, ensure the node is started with `--ws-external` to allow external connections and that no firewalls are blocking the port. For example: `your-node --dev --ws-external`.
Ensure your local type registry is up-to-date. If using a custom chain or a chain with recent runtime upgrades, manually provide the correct `type_registry_preset` or a custom `type_registry` JSON file when initializing `AsyncSubstrateInterface`. You might also try setting `use_remote_preset=True` if supported by the connected node.