beem.steem module

class beem.steem.Steem(node='', rpcuser=None, rpcpassword=None, debug=False, data_refresh_time_seconds=900, **kwargs)

Bases: object

Connect to the Steem network.

Parameters:
  • node (str) – Node to connect to (optional)
  • rpcuser (str) – RPC user (optional)
  • rpcpassword (str) – RPC password (optional)
  • nobroadcast (bool) – Do not broadcast a transaction! (optional)
  • debug (bool) – Enable Debugging (optional)
  • keys (array,dict,string) – Predefine the wif keys to shortcut the wallet database (optional)
  • wif (array,dict,string) – Predefine the wif keys to shortcut the wallet database (optional)
  • offline (bool) – Boolean to prevent connecting to network (defaults to False) (optional)
  • expiration (int) – Delay in seconds until transactions are supposed to expire (optional)
  • blocking (str) – Wait for broadcasted transactions to be included in a block and return full transaction (can be “head” or “irrversible”)
  • bundle (bool) – Do not broadcast transactions right away, but allow to bundle operations (optional)
  • appbase (bool) – Use the new appbase rpc protocol on nodes with version 0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower.
  • num_retries (int) – Set the maximum number of reconnects to the nodes before NumRetriesReached is raised. Disabled for -1. (default is -1)
  • num_retries_call (int) – Repeat num_retries_call times a rpc call on node error (default is 5)
  • timeout (int) – Timeout setting for https nodes (default is 60)

Three wallet operation modes are possible:

  • Wallet Database: Here, the steemlibs load the keys from the locally stored wallet SQLite database (see storage.py). To use this mode, simply call Steem() without the keys parameter
  • Providing Keys: Here, you can provide the keys for your accounts manually. All you need to do is add the wif keys for the accounts you want to use as a simple array using the keys parameter to Steem().
  • Force keys: This more is for advanced users and requires that you know what you are doing. Here, the keys parameter is a dictionary that overwrite the active, owner, posting or memo keys for any account. This mode is only used for foreign signatures!

If no node is provided, it will connect to default nodes of http://geo.steem.pl. Default settings can be changed with:

steem = Steem(<host>)

where <host> starts with https://, ws:// or wss://.

The purpose of this class it to simplify interaction with Steem.

The idea is to have a class that allows to do this:

from beem import Steem
steem = Steem()
print(steem.info())

This class also deals with edits, votes and reading content.

broadcast(tx=None)

Broadcast a transaction to the Steem network

Parameters:tx (tx) – Signed transaction to broadcast
chain_params
clear()
comment_options(options, identifier, account=None)

Set the comment options :param str identifier: Post identifier :param dict options: The options to define. :param str account: (optional) the account to allow access

to (defaults to default_account)
For the options, you have these defaults:::
{
“author”: “”, “permlink”: “”, “max_accepted_payout”: “1000000.000 SBD”, “percent_steem_dollars”: 10000, “allow_votes”: True, “allow_curation_rewards”: True,

}

connect(node='', rpcuser='', rpcpassword='', **kwargs)

Connect to Steem network (internal use only)

create_account(account_name, creator=None, owner_key=None, active_key=None, memo_key=None, posting_key=None, password=None, additional_owner_keys=[], additional_active_keys=[], additional_posting_keys=[], additional_owner_accounts=[], additional_active_accounts=[], additional_posting_accounts=[], storekeys=True, store_owner_key=False, json_meta=None, delegation_fee_steem='0 STEEM', **kwargs)

Create new account on Steem

The brainkey/password can be used to recover all generated keys (see beemgraphenebase.account for more details.

By default, this call will use default_account to register a new name account_name with all keys being derived from a new brain key that will be returned. The corresponding keys will automatically be installed in the wallet.

Warning

Don’t call this method unless you know what you are doing! Be sure to understand what this method does and where to find the private keys for your account.

Note

Please note that this imports private keys (if password is present) into the wallet by default when nobroadcast is set to False. However, it does not import the owner key for security reasons by default. If you set store_owner_key to True, the owner key is stored. Do NOT expect to be able to recover it from the wallet if you lose your password!

Note

Account creations cost a fee that is defined by the network. If you create an account, you will need to pay for that fee! You can partially pay that fee by delegating VESTS. To pay the fee in full in STEEM, leave delegation_fee_steem set to 0 STEEM (Default). To pay the fee partially in STEEM, partially with delegated VESTS, set delegation_fee_steem to a value greater than 1 STEEM. Required VESTS will be calculated automatically. To pay the fee with maximum amount of delegation, set delegation_fee_steem to 1 STEEM. Required VESTS will be calculated automatically.

Parameters:
  • account_name (str) – (required) new account name
  • json_meta (str) – Optional meta data for the account
  • owner_key (str) – Main owner key
  • active_key (str) – Main active key
  • posting_key (str) – Main posting key
  • memo_key (str) – Main memo_key
  • password (str) – Alternatively to providing keys, one can provide a password from which the keys will be derived
  • additional_owner_keys (array) – Additional owner public keys
  • additional_active_keys (array) – Additional active public keys
  • additional_posting_keys (array) – Additional posting public keys
  • additional_owner_accounts (array) – Additional owner account names
  • additional_active_accounts (array) – Additional acctive account names
  • storekeys (bool) – Store new keys in the wallet (default: True)
  • delegation_fee_steem – If set, creator pay a fee of this amount, and delegate the rest with VESTS (calculated automatically). Minimum: 1 STEEM. If left to 0 (Default), full fee is paid without VESTS delegation.
  • creator (str) – which account should pay the registration fee (defaults to default_account)
Raises:

AccountExistsException – if the account already exists on the blockchain

custom_json(id, json_data, required_auths=[], required_posting_auths=[])

Create a custom json operation :param str id: identifier for the custom json (max length 32 bytes) :param json json_data: the json data to put into the custom_json

operation
Parameters:
  • required_auths (list) – (optional) required auths
  • required_posting_auths (list) – (optional) posting auths
finalizeOp(ops, account, permission, **kwargs)

This method obtains the required private keys if present in the wallet, finalizes the transaction, signs it and broadacasts it

Parameters:
  • ops (operation) – The operation (or list of operaions) to broadcast
  • account (operation) – The account that authorizes the operation
  • permission (string) – The required permission for signing (active, owner, posting)
  • append_to (object) – This allows to provide an instance of ProposalsBuilder (see steem.new_proposal()) or TransactionBuilder (see steem.new_tx()) to specify where to put a specific operation.
… note:: append_to is exposed to every method used in the
Steem class

… note:

If ``ops`` is a list of operation, they all need to be
signable by the same key! Thus, you cannot combine ops
that require active permission with ops that require
posting permission. Neither can you use different
accounts for different operations!
… note:: This uses beem.txbuffer as instance of
beem.transactionbuilder.TransactionBuilder. You may want to use your own txbuffer
get_block_interval()

Returns the block intervall in seconds

get_blockchain_version()

Returns the blockchain version

get_chain_properties(use_stored_data=True)

Return witness elected chain properties

::
{‘account_creation_fee’: ‘30.000 STEEM’,
‘maximum_block_size’: 65536, ‘sbd_interest_rate’: 250}
get_config(use_stored_data=True)

Returns internal chain configuration.

get_current_median_history(use_stored_data=True)

Returns the current median price :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

get_default_nodes()

Returns the default nodes

get_dynamic_global_properties(use_stored_data=True)

This call returns the dynamic global properties :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

get_feed_history(use_stored_data=True)

Returns the feed_history :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

get_hardfork_properties(use_stored_data=True)

Returns Hardfork and live_time of the hardfork :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

get_median_price()

Returns the current median history price as Price

get_network(use_stored_data=True)

Identify the network :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

Returns:Network parameters
Return type:dict
get_reserve_ratio(use_stored_data=True)

This call returns the dynamic global properties :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

get_reward_funds(use_stored_data=True)

Get details for a reward fund. :param bool use_stored_data: if True, stored data will be returned. If stored data are empty or old, refresh_data() is used.

get_sbd_per_rshares()

Returns the current rshares to SBD ratio

get_steem_per_mvest(time_stamp=None)

Returns the current mvest to steem ratio

get_witness_schedule(use_stored_data=True)

Return witness elected chain properties

info()

Returns the global properties

is_connected()

Returns if rpc is connected

newWallet(pwd)

Create a new wallet. This method is basically only calls beem.wallet.create().

Parameters:pwd (str) – Password to use for the new wallet
Raises:beem.exceptions.WalletExists – if there is already a wallet created
new_tx(*args, **kwargs)

Let’s obtain a new txbuffer

Returns int txid:
 id of the new txbuffer
post(title, body, author=None, permlink=None, reply_identifier=None, json_metadata=None, comment_options=None, community=None, app=None, tags=None, beneficiaries=None, self_vote=False)

Create a new post. If this post is intended as a reply/comment, reply_identifier needs to be set with the identifier of the parent post/comment (eg. @author/permlink). Optionally you can also set json_metadata, comment_options and upvote the newly created post as an author. Setting category, tags or community will override the values provided in json_metadata and/or comment_options where appropriate. Args: title (str): Title of the post body (str): Body of the post/comment author (str): Account are you posting from permlink (str): Manually set the permlink (defaults to None).

If left empty, it will be derived from title automatically.
reply_identifier (str): Identifier of the parent post/comment (only
if this post is a reply/comment).
json_metadata (str, dict): JSON meta object that can be attached to
the post.
comment_options (str, dict): JSON options object that can be
attached to the post.
Example::
comment_options = {

‘max_accepted_payout’: ‘1000000.000 SBD’, ‘percent_steem_dollars’: 10000, ‘allow_votes’: True, ‘allow_curation_rewards’: True, ‘extensions’: [[0, {

‘beneficiaries’: [
{‘account’: ‘account1’, ‘weight’: 5000}, {‘account’: ‘account2’, ‘weight’: 5000},

]}

]]

}

community (str): (Optional) Name of the community we are posting
into. This will also override the community specified in json_metadata.
app (str): (Optional) Name of the app which are used for posting
when not set, beem/<version> is used
tags (str, list): (Optional) A list of tags (5 max) to go with the
post. This will also override the tags specified in json_metadata. The first tag will be used as a ‘category’. If provided as a string, it should be space separated.
beneficiaries (list of dicts): (Optional) A list of beneficiaries
for posting reward distribution. This argument overrides beneficiaries as specified in comment_options.

For example, if we would like to split rewards between account1 and account2:

beneficiaries = [
    {'account': 'account1', 'weight': 5000},
    {'account': 'account2', 'weight': 5000}
]
self_vote (bool): (Optional) Upvote the post as author, right after
posting.
prefix
refresh_data(force_refresh=False, data_refresh_time_seconds=None)

Read and stores steem blockchain parameters If the last data refresh is older than data_refresh_time_seconds, data will be refreshed

param bool force_refresh:
 if True, data are forced to refreshed
param float data_refresh_time_seconds:
 set a new minimal refresh time in seconds
rshares_to_sbd(rshares)

Calculates the SBD amount of a vote

rshares_to_vote_pct(rshares, steem_power=None, vests=None, voting_power=10000)

Obtain the voting percentage for a desired rshares value for a given Steem Power or vesting shares and voting_power Give either steem_power or vests, not both. When the output is greater than 10000, the given rshares are to high

Returns the voting participation (100% = 10000)

Parameters:
  • rshares (number) – desired rshares value
  • steem_power (number) – Steem Power
  • vests (number) – vesting shares
  • voting_power (int) – voting power (100% = 10000)
set_default_account(account)

Set the default account to be used

set_default_nodes(nodes)

Set the default nodes to be used

set_default_vote_weight(vote_weight)

Set the default vote weight to be used

sign(tx=None, wifs=[])

Sign a provided transaction witht he provided key(s)

Parameters:
  • tx (dict) – The transaction to be signed and returned
  • wifs (string) – One or many wif keys to use for signing a transaction. If not present, the keys will be loaded from the wallet as defined in “missing_signatures” key of the transactions.
sp_to_rshares(steem_power, voting_power=10000, vote_pct=10000)

Obtain the r-shares from Steem power :param number steem_power: Steem Power :param int voting_power: voting power (100% = 10000) :param int vote_pct: voting participation (100% = 10000)

sp_to_sbd(sp, voting_power=10000, vote_pct=10000)

Obtain the resulting sbd amount from Steem power :param number steem_power: Steem Power :param int voting_power: voting power (100% = 10000) :param int vote_pct: voting participation (100% = 10000)

sp_to_vests(sp, timestamp=None)
tx()

Returns the default transaction buffer

txbuffer

Returns the currently active tx buffer

unlock(*args, **kwargs)

Unlock the internal wallet

vests_to_rshares(vests, voting_power=10000, vote_pct=10000)

Obtain the r-shares from vests :param number vests: vesting shares :param int voting_power: voting power (100% = 10000) :param int vote_pct: voting participation (100% = 10000)

vests_to_sbd(vests, voting_power=10000, vote_pct=10000)

Obtain the resulting sbd voting amount from vests :param number vests: vesting shares :param int voting_power: voting power (100% = 10000) :param int vote_pct: voting participation (100% = 10000)

vests_to_sp(vests, timestamp=None)
witness_update(signing_key, url, props, account=None)

Creates/updates a witness :param pubkey signing_key: Signing key :param str url: URL :param dict props: Properties :param str account: (optional) witness account name

Properties:::
{
“account_creation_fee”: x, “maximum_block_size”: x, “sbd_interest_rate”: x,

}