BitShares

The BitShares 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 BitShares blockchain protocol.

class bitshares.bitshares.BitShares(node='', rpcuser='', rpcpassword='', debug=False, **kwargs)

Connect to the BitShares 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 bitshareslibs load the keys from the locally stored wallet SQLite database (see storage.py). To use this mode, simply call BitShares() 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 BitShares().
  • 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://uptick.rocks. It is highly recommended that you pick your own node instead. Default settings can be changed with:

uptick set node <host>

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

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

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

from bitshares import BitShares
bitshares = BitShares()
print(bitshares.info())

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

uptick addkey

and setting a default author:

uptick set default_account xeroc

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

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

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)

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)

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)

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)
approveworker(workers, account=None)

Approve a worker

Parameters:
  • workers (list) – list of worker member name or id
  • account (str) – (optional) the account to allow access to (defaults to default_account)
broadcast(tx=None)

Broadcast a transaction to the BitShares network

Parameters:tx (tx) – Signed transaction to broadcast
cancel(orderNumbers, account=None)

Cancels an order you have placed in a given market. Requires only the “orderNumbers”. An order number takes the form 1.7.xxx.

Parameters:orderNumbers (str) – The Order Object ide of the form 1.7.xxxx
connect(node='', rpcuser='', rpcpassword='', **kwargs)

Connect to BitShares network (internal use only)

create_account(account_name, registrar=None, referrer='1.2.35641', 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)

Create new account on BitShares

The brainkey/password can be used to recover all generated keys (see bitsharesbase.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

create_worker(name, daily_pay, end, url='', begin=None, payment_type='vesting', pay_vesting_period_days=0, account=None)

Reserve/Burn an amount of this shares

This removes the shares from the supply

Required

Parameters:
  • name (str) – Name of the worke
  • daily_pay (bitshares.amount.Amount) – The amount to be paid daily
  • end (datetime) – Date/time of end of the worker

Optional

Parameters:
  • url (str) – URL to read more about the worker
  • begin (datetime) – Date/time of begin of the worker
  • payment_type (string) – [“burn”, “refund”, “vesting”] (default: “vesting”)
  • pay_vesting_period_days (int) – Days of vesting (default: 0)
  • account (str) – (optional) the account to allow access to (defaults to default_account)
disallow(foreign, permission='active', account=None, threshold=None)

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)

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)

Disapprove Proposal

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

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)
disapproveworker(workers, account=None)

Disapprove a worker

Parameters:
  • workers (list) – list of worker name or id
  • account (str) – (optional) the account to allow access to (defaults to default_account)
finalizeOp(ops, account, permission)

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)

... 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!
info()

Returns the global properties

newWallet(pwd)

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

Parameters:pwd (str) – Password to use for the new wallet
Raises:bitshares.exceptions.WalletExists – if there is already a wallet created
publish_price_feed(symbol, settlement_price, cer=None, mssr=110, mcr=200, account=None)

Publish a price feed for a market-pegged asset

Parameters:
  • symbol (str) – Symbol of the asset to publish feed for
  • settlement_price (bitshares.price.Price) – Price for settlement
  • cer (bitshares.price.Price) – Core exchange Rate (default settlement_price + 5%)
  • mssr (float) – Percentage for max short squeeze ratio (default: 110%)
  • mcr (float) – Percentage for maintenance collateral ratio (default: 200%)
  • account (str) – (optional) the account to allow access to (defaults to default_account)

Note

The account needs to be allowed to produce a price feed for symbol. For witness produced feeds this means account is a witness account!

reserve(amount, account=None)

Reserve/Burn an amount of this shares

This removes the shares from the supply

Parameters:
  • amount (bitshares.amount.Amount) – The amount to be burned.
  • account (str) – (optional) the account to allow access to (defaults to default_account)
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.
transfer(to, amount, asset, memo='', account=None)

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
update_memo_key(key, account=None)

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)
update_witness(witness_identifier, url=None, key=None)

Upgrade a witness account

Parameters:
  • witness_identifier (str) – Identifier for the witness
  • url (str) – New URL for the witness
  • key (str) – Public Key for the signing
upgrade_account(account=None)

Upgrade an account to Lifetime membership

Parameters:account (str) – (optional) the account to allow access to (defaults to default_account)
vesting_balance_withdraw(vesting_id, amount=None, account=None)

Withdraw vesting balance

Parameters:
  • vesting_id (str) – Id of the vesting object
  • Amount (bitshares.amount.Amount) – to withdraw (“all” if not provided”)
  • account (str) – (optional) the account to allow access to (defaults to default_account)