Skip to main content

aiothornode

This is a simple Python library to access THORChain nodes. It is asynchronous and uses aiohttp.

Important

v.0.1.0 breaking changes:

  1. NamedTuples instead of DataClasses for Thor entities
  2. Environments were renamed
  3. No more consensus features

v.0.0.21 is hotfix. Port 1317 was disabled, so it is an emergency upgrade to save this lib. More news will be later...

Features:

  • Now it is just a convenient wrapper for THORNode API

Supported endpoints:

  • Constants
  • Mimir
  • Nodes (node accounts)
  • Current TX queue length
  • Pools (current and at arbitrary height)
  • Tendermint block at height
  • Inbound addresses and other chain info
  • Asgard & Yggdrasil vaults (new!)
  • Balance of THOR account

Installation

python -m pip install git+https://github.com/tirinox/aiothornode

Quick start

The following code is quite self-documenting:

import random

from aiothornode.connector import *
from aiothornode.env import *
import asyncio
import aiohttp


def delim():
    print('-' * 100)


async def main():
    env = MAINNET.copy()
    # env = ThorEnvironment(...)  # custom

    async with aiohttp.ClientSession() as session:
        connector = ThorConnector(env, session)

        genesis = await connector.query_genesis()
        print(f'Chain ID = {genesis["chain_id"]}')
        delim()

        chains = await connector.query_chain_info()
        chains = list(chains.values())
        print('Chain info:', chains)
        delim()

        print('Tendermint Block:')
        tender_block = await connector.query_tendermint_block_raw(100001)
        block_header = tender_block['result']['block']['header']
        print(f'{block_header["height"] = } and {block_header["time"] = }')
        delim()

        constants = await connector.query_constants()
        print(f'Constants: {constants}')
        delim()

        mimir = await connector.query_mimir()
        mimir_1 = mimir.get('MINIMUMBONDINRUNE')
        print(f'Mimir: {mimir}, MINIMUMBONDINRUNE = {mimir_1}')
        delim()

        queue = await connector.query_queue()
        print(f'Queue: {queue}')
        delim()

        node_accounts = await connector.query_node_accounts(consensus=False)
        print(f'Example node account: {random.sample(node_accounts, 1)[0]}')
        delim()

        pool = await connector.query_pool('BNB.BUSD-BD1', height=8218339)
        print(pool)
        delim()

        pools = await connector.query_pools()
        print(pools[0])
        print(f'Total {len(pools)} pools')
        delim()

        bank = await connector.query_balance('thor1dheycdevq39qlkxs2a6wuuzyn4aqxhve4qxtxt')
        print(f'Balance of {bank.address} is {bank.runes_float} Rune')
        delim()


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

Testing

Install PyTest and an async plugin for it:

pip install pytest
pip install pytest-asyncio

Then run

pytest test

Metadata

Release files for aiothornode 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiothornode 0.1.7
File Size Uploaded
aiothornode-0.1.7.tar.gz 15.0 kB Details

Release files / aiothornode-0.1.7.tar.gz

Download URL aiothornode-0.1.7.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
33dcb40758cb3c519c1fb986dd4c856d361737e4c73ef4d1d555df059c49c494
BLAKE2b-256 checksum
How to use checksums
0916292af8096430e6f62a5156f4fdf2bdf5c6c8142fb6875eda84848482cf1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.1.7 This release

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.24

1 release file

0.0.23

1 release file

0.0.22

1 release file

0.0.21

1 release file

0.0.20

1 release file

0.0.19

1 release file

0.0.18

1 release file

0.0.17

1 release file

0.0.16

1 release file

0.0.15

1 release file

0.0.14

1 release file

0.0.12

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page