to Other APIs Using advanced APIs 3 Abstraction Layer: Piston Signed Transactions Writing to Steem Monitoring the Blockchain 4 Live Coding 5 Further Reading 2/26
Blockchain Database Database API Account History API Market History API Tag API Follow API Broadcast API … steemd ✓ JSON formatted Remote Procedure Calls (RPC) via HTTP × No need to understand blockchain technology × No need to understand consensus schemes × No need to understand P2P networks × No need to know the protocol 4/26
good for? Database API: Database API: get_trending_tags() get_state() get_block() get_account() … Market History API (Plugin): Market History API (Plugin): get_ticker() get_trade_history() get_recent_trades() get_volume() … Broadcast API (Plugin): Broadcast API (Plugin): broadcast_transaction() broadcast_transaction_synchronous() … Follow API (Plugin): Follow API (Plugin): get_followers() get_following() get_feed() … 5/26
0) is enabled and accessible by default! For every other API a identifier needs to be requested! The python-steem library simplifies this > {"method": "call", "jsonrpc": "2.0", "id": 1, "params": [1, "login", ["<user>","<password>"]]} < {"id":1,"result":true} > {"method": "call", "jsonrpc": "2.0", "id": 2, "params": [1, "get_api_by_name",["network_broadcast_api"]]} < {"id":2,"result":5} 9/26
the API number obtained in the previous step: > {"method": "call", "jsonrpc": "2.0", "id": 3, "params": [ 5, "broadcast_transaction_synchronous", ["<signed_transaction>"] ]} < {"id":1,"result":Null} 11/26
Steem blockchain! Developed to make live easier for developers and user Multiple Abstraction Layers involved: python-graphene python-steem piston Uses public API server: this.piston.rocks and node.steem.ws 13/26
Steem? Writing to the blockchain requires: an account the (posting, or active) private key “letters of intent”: vote, or comment, or transfer, etc. Providing Keys to Piston: > piston addkeys # Shell command to use the internal wallet >>> steem = Steem(keys=["5xxxxx", "5xxxxx"]) # Provide a list of keys # Advanced users can force keys for signing >>> steem = Steem(keys={ "owner": "5xxxxx", "active": "5xxxxx", "posting": "5xxxxx", "memo": "5xxxxx", }) 16/26
is provided by python-graphene and is not part of this talk. All piston methods that “write to” the blockchain return a (partially) signed transaction of the above form. >>> from piston.steem import Steem >>> steem = Steem(nobroadcast=True) >>> print(steem.transfer(to="fabian", account="xeroc", amount=1, asset="SBD")) Passphrase: *********** Not broadcasting anything... {'ref_block_prefix': 2732406441, 'ref_block_num': 21994, 'expiration': '2016-11-09T15:08:00', 'operations': [['transfer', { 'from': 'xeroc', 'memo': '', 'to': 'fabian', 'amount': '1.000 SBD'}]], 'extensions': [], 'signatures': ['202ceb735d3c1e3b22be63b...96d5d136e41958156716de'] } 18/26
represented using the Post abstraction class which adds post-specific methods that correspond to this particular post: post = steem.get_content("@xeroc/piston") post.upvote() post.reply("You rock!") print(post.url) print(post["url"]) print(post.author) print(post.title) print(post.body) print(post.author_rewards) print(post.net_votes) print(post.get_comments()) # again returns Post instances ... 21/26
for post in steem.stream_comments(): if not post.depth: print(post.body) Monitoring Raw Blocks Monitoring Raw Blocks for block in steem.rpc.block_stream(): print(block["block_num"]) Monitoring Specific Operations Monitoring Specific Operations for op in steem.rpc.stream(["transfer", "vote"]): print(op) 23/26