Skip to main content

This is a simple gRPC client for a python application which communiactes with the Kaspa node called KASPAD. Note: This module is created for the RUST version and might be not compatible with the go written node.

Project description

This is a simple gRPC client for a python application which communiactes with the Kaspa node called KASPAD.

The module is based on asyncio, since the Kaspa BlockDAG is unbelievable fast and also needs the support of notifications.

Usage: see playground.py

import asyncio

from kaspad_client.modules.KaspadClient import KaspadClient


async def main():
    kaspad_client = KaspadClient("127.0.0.1", 16110)

    # print the info message
    print(await kaspad_client.get_info())

    # returns
    # {'getInfoResponse': {'p2pId': 'a9728d7e-c07b-4641-936c-6c7442b819f8', 'serverVersion': '0.13.4',
    # 'isUtxoIndexed': True, 'isSynced': True, 'hasNotifyCommand': True, 'hasMessageId': True,
    # 'mempoolSize': '0'}, 'id': '0'}


    # now let's set up some notifications
    # the decorator registers an async callback function and requests the notification automatically

    @kaspad_client.notify_virtual_daa_score_changed
    async def received_new_daa_score(c):
        print(f"The DAA score is: {c['virtualDaaScoreChangedNotification']['virtualDaaScore']}")

    @kaspad_client.notify_virtual_daa_score_changed
    async def received_new_daa_score2(c):
        print(f"The DAA2 score is: {c['virtualDaaScoreChangedNotification']['virtualDaaScore']}")

    @kaspad_client.notify_block_added
    async def received_new_daa_score(c):
        print(f"New Kaspa block: {c['blockAddedNotification']['block']['verboseData']['hash']}")

    # wait to see some notifcations :-)
    await asyncio.sleep(60)



asyncio.run(main())

Donation

We are doing this in our free time. Please consider a donation if this helps! Thank you!

kaspa:qrlsm9tvmak6909pr9f35g6scapz5t689nhhls54sfxx5m46sn085ajhn9hn8

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kaspad_client-1.0.4.tar.gz (22.0 kB view hashes)

Uploaded Source

Built Distribution

kaspad_client-1.0.4-py3-none-any.whl (25.0 kB view hashes)

Uploaded Python 3

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