PeerPlays

The PeerPlays library has been designed to allow developers to easily access its routines and make use of the network without dealing with all the related blockchain technology and cryptography. This library can be used to do anything that is allowed according to the PeerPlays blockchain protocol.

class peerplays.peerplays.PeerPlays(node='', rpcuser='', rpcpassword='', debug=False, **kwargs)

Connect to the PeerPlays 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)
  • offline (bool) – Boolean to prevent connecting to network (defaults to False) (optional)
  • proposer (str) – Propose a transaction using this proposer (optional)
  • proposal_expiration (int) – Expiration time (in seconds) for the proposal (optional)
  • proposal_review (int) – Review period (in seconds) for the proposal (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)

Three wallet operation modes are possible:

  • Wallet Database: Here, the peerplayslibs load the keys from the locally stored wallet SQLite database (see storage.py). To use this mode, simply call PeerPlays() 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 PeerPlays().
  • 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, or memo keys for any account. This mode is only used for foreign signatures!

If no node is provided, it will connect to the node of http://ppy-node.peerplays.eu. It is highly recommended that you pick your own node instead. Default settings can be changed with:

peerplays set node <host>

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

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

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

from peerplays import PeerPlays
peerplays = PeerPlays()
print(peerplays.info())

All that is requires is for the user to have added a key with peerplays

peerplays addkey

and setting a default author:

peerplays set default_account xeroc

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

allow(foreign, weight=None, permission='active', account=None, threshold=None, **kwargs)

Give additional access to an account by some other public key or account.

Parameters:
  • foreign (str) – The foreign account that will obtain access
  • weight (int) – (optional) The weight to use. If not define, the threshold will be used. If the weight is smaller than the threshold, additional signatures will be required. (defaults to threshold)
  • permission (str) – (optional) The actual permission to modify (defaults to active)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
  • threshold (int) – The threshold that needs to be reached by signatures to be able to interact
approvecommittee(committees, account=None, **kwargs)

Approve a committee

Parameters:
  • committees (list) – list of committee member name or id
  • account (str) – (optional) the account to allow access to (defaults to default_account)
approveproposal(proposal_ids, account=None, approver=None, **kwargs)

Approve Proposal

Parameters:
  • proposal_id (list) – Ids of the proposals
  • account (str) – (optional) the account to allow access to (defaults to default_account)
approvewitness(witnesses, account=None, **kwargs)

Approve a witness

Parameters:
  • witnesses (list) – list of Witness name or id
  • account (str) – (optional) the account to allow access to (defaults to default_account)
bet_cancel(bet_to_cancel, account=None, **kwargs)

Cancel a bet

Parameters:
  • bet_to_cancel (str) – The identifier that identifies the bet to cancel
  • account (str) – (optional) the account that owns the bet (defaults to default_account)
bet_place(betting_market_id, amount_to_bet, backer_multiplier, back_or_lay, account=None, **kwargs)

Place a bet

Parameters:
  • betting_market_id (str) – The identifier for the market to bet in
  • amount_to_bet (peerplays.amount.Amount) – Amount to bet with
  • backer_multiplier (int) – Multipler for backer
  • back_or_lay (str) – “back” or “lay” the bet
  • account (str) – (optional) the account to bet (defaults to default_account)
betting_market_create(payout_condition, description, group_id='0.0.0', account=None, **kwargs)

Create an event group. This needs to be proposed.

Parameters:
  • payout_condition (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • description (list) – Internationalized descriptions, e.g. [['de', 'Foo'], ['en', 'bar']]
  • group_id (str) – Group ID to create the market for (defaults to relative id 0.0.0)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
betting_market_group_create(description, event_id='0.0.0', rules_id='0.0.0', asset=None, account=None, **kwargs)

Create an betting market. This needs to be proposed.

Parameters:
  • description (list) – Internationalized list of descriptions
  • event_id (str) – Event ID to create this for (defaults to relative id 0.0.0)
  • rule_id (str) – Rule ID to create this with (defaults to relative id 0.0.0)
  • asset (peerplays.asset.Asset) – Asset to be used for this market
  • account (str) – (optional) the account to allow access to (defaults to default_account)
betting_market_group_update(betting_market_group_id, description, event_id='0.0.0', rules_id='0.0.0', freeze=False, delay_bets=False, account=None, **kwargs)

Update an betting market. This needs to be proposed.

Parameters:
  • betting_market_group_id (str) – Id of the betting market group to update
  • description (list) – Internationalized list of descriptions
  • event_id (str) – Event ID to create this for (defaults to relative id 0.0.0)
  • rule_id (str) – Rule ID to create this with (defaults to relative id 0.0.0)
  • freeze (bool) – Freeze the MBG
  • delay_bets (bool) – Delay betting
  • account (str) – (optional) the account to allow access to (defaults to default_account)
betting_market_resolve(betting_market_group_id, results, account=None, **kwargs)

Create an betting market. This needs to be proposed.

Parameters:
  • betting_market_group_id (str) – Market Group ID to resolve
  • results (list) – Array of Result of the market (win, not_win, or cancel)
  • account (str) – (optional) the account to allow access to (defaults to default_account)

Results take the form::

 [
    ["1.21.257", "win"],
    ["1.21.258", "not_win"],
    ["1.21.259", "cancel"],
]
betting_market_rules_create(names, descriptions, account=None, **kwargs)

Create betting market rules

Parameters:
  • names (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • descriptions (list) – Internationalized descriptions, e.g. [['de', 'Foo'], ['en', 'bar']]
  • account (str) – (optional) the account to allow access to (defaults to default_account)
betting_market_rules_update(rules_id, names, descriptions, account=None, **kwargs)

Update betting market rules

Parameters:
  • rules_id (str) – Id of the betting market rules to update
  • names (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • descriptions (list) – Internationalized descriptions, e.g. [['de', 'Foo'], ['en', 'bar']]
  • account (str) – (optional) the account to allow access to (defaults to default_account)
betting_market_update(betting_market_id, payout_condition, description, group_id='0.0.0', account=None, **kwargs)

Update an event group. This needs to be proposed.

Parameters:
  • betting_market_id (str) – Id of the betting market to update
  • payout_condition (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • description (list) – Internationalized descriptions, e.g. [['de', 'Foo'], ['en', 'bar']]
  • group_id (str) – Group ID to create the market for (defaults to relative id 0.0.0)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
broadcast(tx=None)

Broadcast a transaction to the PeerPlays network

Parameters:tx (tx) – Signed transaction to broadcast
connect(node='', rpcuser='', rpcpassword='', **kwargs)

Connect to Steem network (internal use only)

create_account(account_name, registrar=None, referrer='1.2.0', referrer_percent=50, owner_key=None, active_key=None, memo_key=None, password=None, additional_owner_keys=[], additional_active_keys=[], additional_owner_accounts=[], additional_active_accounts=[], proxy_account='proxy-to-self', storekeys=True, **kwargs)

Create new account on PeerPlays

The brainkey/password can be used to recover all generated keys (see peerplaysbase.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. However, it does not import the owner key for security reasons. Do NOT expect to be able to recover it from the wallet if you lose your password!

Parameters:
  • account_name (str) – (required) new account name
  • registrar (str) – which account should pay the registration fee (defaults to default_account)
  • owner_key (str) – Main owner key
  • active_key (str) – Main active 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_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)
Raises:

AccountExistsException – if the account already exists on the blockchain

disallow(foreign, permission='active', account=None, threshold=None, **kwargs)

Remove additional access to an account by some other public key or account.

Parameters:
  • foreign (str) – The foreign account that will obtain access
  • permission (str) – (optional) The actual permission to modify (defaults to active)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
  • threshold (int) – The threshold that needs to be reached by signatures to be able to interact
disapprovecommittee(committees, account=None, **kwargs)

Disapprove a committee

Parameters:
  • committees (list) – list of committee name or id
  • account (str) – (optional) the account to allow access to (defaults to default_account)
disapproveproposal(proposal_ids, account=None, approver=None, **kwargs)

Disapprove Proposal

Parameters:
  • proposal_ids (list) – Id of the proposals
  • account (str) – (optional) the account to allow access to (defaults to default_account)
disapprovewitness(witnesses, account=None, **kwargs)

Disapprove a witness

Parameters:
  • witnesses (list) – list of Witness name or id
  • account (str) – (optional) the account to allow access to (defaults to default_account)
event_create(name, season, start_time, event_group_id='0.0.0', account=None, **kwargs)

Create an event. This needs to be proposed.

Parameters:
  • name (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • season (list) – Internationalized season, e.g. [['de', 'Foo'], ['en', 'bar']]
  • event_group_id (str) – Event group ID to create the event for (defaults to relative id 0.0.0)
  • start_time (datetime) – Time of the start of the event
  • account (str) – (optional) the account to allow access to (defaults to default_account)
event_group_create(names, sport_id='0.0.0', account=None, **kwargs)

Create an event group. This needs to be proposed.

Parameters:
  • names (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • sport_id (str) – Sport ID to create the event group for (defaults to relative id 0.0.0)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
event_group_update(event_group_id, names=[], sport_id='0.0.0', account=None, **kwargs)

Update an event group. This needs to be proposed.

Parameters:
  • event_id (str) – Id of the event group to update
  • names (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • sport_id (str) – Sport ID to create the event group for (defaults to relative id 0.0.0)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
event_update(event_id, name, season, start_time, event_group_id='0.0.0', account=None, **kwargs)

Update an event. This needs to be proposed.

Parameters:
  • event_id (str) – Id of the event to update
  • name (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • season (list) – Internationalized season, e.g. [['de', 'Foo'], ['en', 'bar']]
  • event_group_id (str) – Event group ID to create the event for (defaults to relative id 0.0.0)
  • start_time (datetime) – Time of the start of the event
  • account (str) – (optional) the account to allow access to (defaults to default_account)
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 peerplays.new_proposal()) or TransactionBuilder (see peerplays.new_tx()) to specify where to put a specific operation.
... note:: append_to is exposed to every method used in the
PeerPlays 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 peerplays.txbuffer as instance of
peerplays.transactionbuilder.TransactionBuilder. You may want to use your own txbuffer
info()

Returns the global properties

newWallet(pwd)

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

Parameters:pwd (str) – Password to use for the new wallet
Raises:peerplays.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
propbuffer

Return the default proposal buffer

proposal(proposer=None, proposal_expiration=None, proposal_review=None)

Return the default proposal buffer

... note:: If any parameter is set, the default proposal
parameters will be changed!
set_default_account(account)

Set the default account 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.
sport_create(names, account=None, **kwargs)

Create a sport. This needs to be proposed.

Parameters:
  • names (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • account (str) – (optional) the account to allow access to (defaults to default_account)
sport_update(sport_id, names=[], account=None, **kwargs)

Update a sport. This needs to be proposed.

Parameters:
  • sport_id (str) – The id of the sport to update
  • names (list) – Internationalized names, e.g. [['de', 'Foo'], ['en', 'bar']]
  • account (str) – (optional) the account to allow access to (defaults to default_account)
transfer(to, amount, asset, memo='', account=None, **kwargs)

Transfer an asset to another account.

Parameters:
  • to (str) – Recipient
  • amount (float) – Amount to transfer
  • asset (str) – Asset to transfer
  • memo (str) – (optional) Memo, may begin with # for encrypted messaging
  • account (str) – (optional) the source account for the transfer if not default_account
tx()

Returns the default transaction buffer

txbuffer

Returns the currently active tx buffer

update_memo_key(key, account=None, **kwargs)

Update an account’s memo public key

This method does not add any private keys to your wallet but merely changes the memo public key.

Parameters:
  • key (str) – New memo public key
  • account (str) – (optional) the account to allow access to (defaults to default_account)
upgrade_account(account=None, **kwargs)

Upgrade an account to Lifetime membership

Parameters:account (str) – (optional) the account to allow access to (defaults to default_account)