Skip to content

How to subscribe events #306

Answered by arjanz
chabashilah asked this question in Q&A
Discussion options

You must be logged in to vote

Good news, since latest release https://github.com/polkascan/py-substrate-interface/releases/tag/v0.12.1 storage subscriptions are possible, so for example to subscribe to events:

def subscription_handler(obj, update_nr, subscription_id):

    # Do something with the update
    print('Events:', obj.value)

    # The execution will block until an arbitrary value is returned, which will be the result of the `query`
    if update_nr > 5:
        return {'updates': update_nr, 'message': 'processed events'}


result = substrate.query("System", "Events", [], subscription_handler=subscription_handler)

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by arjanz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #83 on January 03, 2023 15:13.