steem python robot manages the steem account created by beempy and keys through the JSON file
hive-180932·@dappcoder·
0.000 HBDsteem python robot manages the steem account created by beempy and keys through the JSON file
Steem uses hierarchical authorization, so a steem account has four keys: "owner", "active", "posting", "Memo" These keys are very long. It's not realistic to remember them by human brain. They can only be stored in files and read and written by robots themselves. Last time I demonstrated how to use beempy, now let the creation process use JSON file management. [< Beempy creates a new steem account by using the pending claimed accounts collected by RC >](/@dappcoder/beempy-creates-a-new-steem-account-by-using-the-pending-claimed-accounts-collected-by-rc) Format of JSON file storage(/bots.json): ```json { "nodes": [ "https://anyx.io", "https://api.steemit.com" ], "steems": { "steemaccount": { } } } ``` Demo for creating a new account to store in the JSON file with beempy(create_claimed_account_beem.py): -------------------------------------- ```python #!/usr/bin/python # -*- coding: UTF-8 -*- # python create_claimed_account_beem.py creator account import sys import getopt import time import json # from beem import Steem from beem.account import Account from beem.instance import shared_steem_instance from beemgraphenebase.account import BrainKey, PasswordKey try: creator = sys.argv[1] account = sys.argv[2] except Exception as e: sys.exit() print('creator:', creator) print('account:', account) stm = shared_steem_instance() # Enter the local wallet password or set value directly in the code password = '' # 'walletkey' if not password: password = input('local wallet password : ') stm.wallet.unlock(password) accounts_file = '/bots.json' try: creatorA = Account(creator, steem_instance=stm) accountA = Account(account, steem_instance=stm) except Exception as e: print('account can be created:', account) bk = BrainKey() brainkey = bk.get_brainkey() print('brain key:', str(brainkey)) prikey = str(bk.get_private()) print('private key:', str(prikey)) pubkey = format(bk.get_public(), "STM") print('public key:', str(pubkey)) tx = stm.create_claimed_account( account, creator=creatorA, password=prikey, store_owner_key=True) print('create_claimed_account:', json.dumps(tx, indent=4)) posting_key = PasswordKey(account, prikey, role="posting", prefix=stm.prefix) active_key = PasswordKey(account, prikey, role="active", prefix=stm.prefix) memo_key = PasswordKey(account, prikey, role="memo", prefix=stm.prefix) owner_key = PasswordKey(account, prikey, role="owner", prefix=stm.prefix) memo_pubkey = memo_key.get_public_key() active_privkey = active_key.get_private_key() posting_privkey = posting_key.get_private_key() owner_privkey = owner_key.get_private_key() memo_privkey = memo_key.get_private_key() print('posting_privkey:', str(posting_privkey)) print('active_privkey:', str(active_privkey)) print('owner_privkey:', str(owner_privkey)) print('memo_privkey:', str(memo_privkey)) with open(accounts_file, 'r', encoding='utf-8') as f: accounts_dict = json.load(f) # print('old.accounts_dict:', accounts_dict) accounts_dict['steems'][account] = { "name": account, # steem 账号名称 "email": "sample@,pwd", # steem 注册 email "mobile": "sample9,from", # steem 注册 手机号 "keys": { "brain": brainkey, # steem 账号的脑密码 "private": prikey, # steem 账号当前的私钥 "public": pubkey, # steem 账号当前的公钥 "history": [ # steem 账号的私钥的修改记录 prikey, "sample2", "sample3" ], "posting": str(posting_privkey), # steem 账号的 posting 私钥 "active": str(active_privkey), # steem 账号的 active 私钥 "owner": str(owner_privkey), # steem 账号的 owner 私钥 "memo": str(memo_privkey), # steem 账号的 memo 私钥,用于解密memo "memo_key": str(memo_pubkey) # steem 账号的 memo 公钥,用于加密memo } } with open(accounts_file, 'w', encoding='utf-8') as f: json.dump(accounts_dict, f, indent=4, ensure_ascii=False) ``` Run it:`python create_claimed_account_beem dappcoder newaccddd` Results consistent with expectations. 中文版本: --------------- [《python开发steem机器人,通过json文件管理beempy创建的steem账号密码》](/@dappcoder/python-steem-json-beempy-steem)
👍 stmdev, tonimontana, haxxdump, mindtrap-leo, tonimontana.leo, tonimontana.neo, exe8422, pixresteemer, anonyvoter, laissez-faire, dblogvoter, neoxvoter, creavoter, steem-holder, trust187, pixelfan, xiguang, ctime, goodcurator, goodvoter, goodreader, goodposter, goodauthor, staryao, acu.fund, anonymity.inlet, huarennews, downvoter, downscaner, tex.fund, xinhuaren, missingwolf, spbank, mana.bank, hnt, acufund, alanyao, yaowl, manabot, manabot1, acu.fund.witness, wang.han, manabot2, manabot3, manabot4, manabank, lvziyun, dappcoder, huaren.news, coolvoter, busy.org, chinesebi, cn-leo, qukehan, sherryzhou, texfund, duckmast3r, steem-drivers, aaronli.sct, cricklu,