-
-
Save tiotdev/ffdecb9992e7163f7cf483aaaa01ebce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://steemit.com/beem/@holger80/how-to-use-beem-for-offline-trx-building-and-signing | |
import json | |
import requests | |
from beem.steem import Steem | |
from beem.transactionbuilder import TransactionBuilder | |
from beembase import operations | |
from beembase.transactions import getBlockParams | |
# Account config | |
account = 'jpphotography' | |
wlspostingkey = '' | |
# Node config | |
wlsnode = 'https://pubrpc.whaleshares.io/' | |
# Post config | |
permlink = 'testing-for-steem2wls' | |
title = 'Testing' | |
body = 'Please ignore this' | |
parent_author = '' | |
parent_permlink = 'test' | |
if __name__ == '__main__': | |
wls = Steem(node=wlsnode, nobroadcast=True, prefix='WLS') | |
ref_block_num, ref_block_prefix = getBlockParams(wls) | |
comment = {'title': title, 'body': body, 'author': account, 'permlink': permlink, | |
'parent_author': parent_author, 'parent_permlink': parent_permlink} | |
op = operations.Comment(comment) | |
# Build and sign transaction | |
tb = TransactionBuilder(steem_instance=wls, expiration=3600) | |
tb.appendOps([op]) | |
tb.appendWif(wlspostingkey) | |
tb.constructTx(ref_block_num=ref_block_num, | |
ref_block_prefix=ref_block_prefix) | |
tx = tb.sign(reconstruct_tx=False) | |
# Build transaction in new Whaleshares format | |
params = (tx.json()) | |
ref_block_num = params.get('ref_block_num') | |
ref_block_prefix = params.get('ref_block_prefix') | |
expiration = params.get('expiration') | |
signatures = params.get('signatures') | |
operations = ['social_action', { | |
'account': account, 'action': [0, comment]}] | |
callparams = ['network_broadcast_api', 'broadcast_transaction_synchronous', [ | |
{'ref_block_num': ref_block_num, 'ref_block_prefix': ref_block_prefix, 'expiration': expiration, 'operations': [operations], 'extensions':[], 'signatures':signatures}]] | |
broadcast_json = { | |
'jsonrpc': '2.0', 'method': 'call', 'params': callparams, 'id': 2} | |
# Broadcast transaction | |
req = requests.post(wlsnode, data=json.dumps(broadcast_json)) | |
# Print response | |
print(req.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment