Steem Developer logo

Steem Developer Portal

PY: Stream Blockchain Transactions

How to stream transactions on the live Steem blockchain

Full, runnable src of Stream Blockchain Transactions can be downloaded as part of the PY tutorials repository.

In this tutorial we show you how to stream transactions on the Steem blockchain using the blockchain class found within the steem-python library.

Intro

Tutorial is demonstrating the typical process of streaming blocks on Steem. We will show some information from each block that is being streamed to give you an idea. Each block contains transactions objects as well but we will not show each of this data in user interface.

We are using the blockchain.stream() function provided by steem-python which returns each block after it has been accepted by witnesses. By default it follows irreversible blocks which was accepted by all witnesses.

Steps

  1. App setup Configure imports and initialization of libraries
  2. Stream blocks Stream blocks
  3. Sample result Stream blocks

1. App setup

In this tutorial we use 1 package:

steem - steem-python library and interaction with Blockchain

from steem.blockain import Blockchain

blockchain = Blockchain()

Above we create an instance of Blockchain which will give us the ability to stream the live transactions from the blockchain.

2. Stream blocks

Next we create an instance of stream and then loop through the steam as transactions are available and print them to the screen.

stream = blockchain.stream()

for post in stream:
	print(post)

3. Sample result

{
  "curator": "idx",
  "reward": "4.042446 VESTS",
  "comment_author": "blackbunny",
  "comment_permlink": "6tfv5e",
  "_id": "5801d1c99ca7ecd1d4387ebd89d4edab08612b35",
  "type": "curation_reward",
  "timestamp": "2018-09-21T21:11:02.005Z",
  "block_num": 26136919,
  "trx_id": "0000000000000000000000000000000000000000"
}

That’s it!

To Run the tutorial

  1. review dev requirements
  2. clone this repo
  3. cd tutorials/13_stream_blockchain_transactions
  4. pip install -r requirements.txt
  5. python index.py
  6. After a few moments, you should see a prompt for input in terminal screen.