Api

class golos.api.Api(nodes: Union[List[str], str] = None, **kwargs)[source]

Main class for golos-python - wraps ws_client and provides many helper methods for interacting with the GOLOS blockchain, such as get_accounts() and transfer()

Official Repo: https://github.com/Privex/golos-python

Official PyPi Package Name: golos-python

Basic Usage:

>>> from golos import Api
>>> golos = Api()
>>> acc = golos.get_accounts(['someguy123'])
>>> acc[0]['owner']
'someguy123'
>>> wit = golos.get_witness_by_account('someguy123')
>>> wit['url']
'https://golos.io/ru--delegaty/@someguy123/delegat-someguy123'
__init__(nodes: Union[List[str], str] = None, **kwargs)[source]

Constructor for Privex’s GOLOS wrapper class. No arguments are required, unless you want to override defaults.

Basic Usage:

Use default nodes list and settings:

>>> golos = Api()

Use only this specific node:

>>> golos = Api(nodes='wss://golosd.privex.io')

Use a list of nodes, and enable more verbose logging from WsClient

>>> nodes = ['wss://golosd.privex.io', 'wss://api.golos.blckchnd.com/ws']
>>> golos = Api(nodes=nodes, report=True)

Making basic API calls:

>>> acc = golos.get_accounts(['someguy123'])
>>> acc[0]['owner']
'someguy123'
>>> wit = golos.get_witness_by_account('someguy123')
>>> wit['url']
'https://golos.io/ru--delegaty/@someguy123/delegat-someguy123'
Parameters
  • nodes (list|str) – A list / singular str GOLOS node(s) formatted like such: wss://golosd.privex.io

  • report (bool) – (KWARG) If True - enables more verbose logging from WsClient

  • kwargs – Any additional keyword arguments (will be forwarded to WsClient’s constructor)

Methods

__init__([nodes])

Constructor for Privex’s GOLOS wrapper class.

account_create(login, password, creator, …)

account_create_with_delegation(login, …)

account_metadata(account, json_metadata, wif)

account_update(new_password, account, …)

account_update_password(account, password, wif)

account_witness_proxy(account, proxy, wif)

change_recovery_account(account, …)

check_login(login)

convert_golos_to_vests(amount)

delegate_vesting_shares(delegatee, amount, …)

delegate_vesting_shares_with_interest(…)

follow(wtf, followings, followers, wif, **kwargs)

get_account_count()

get_account_history(account, **kwargs)

get_account_reputations(account)

get_accounts(logins, **kwargs)

Перерасчитываются некоторые параметры по аккаунту “voting_power” - 1..10000 реальная батарейка “golos_power” - сила голоса с учетом делегирования “rshares” - сколько добавится шаров в пост при 100% батарейке “GOLOS”, “GBG” - ликвидные токены “new_post_limit” - сколько постов можно опубликовать “new_post_time” - сколько осталось времени в минутах до публикации без штрафа “bandwidth” = { “avail” - всего доступно в кБ “used_forum” - использовано в кБ “used_market” - использовано в кБ “free_forum” - доступно в кБ “free_market” - доступно в кБ } “value” = {“GOLOS”, “GBG”} - цена апвота по внутренней бирже “order” = {“GOLOS”, “GBG”} - цена апвота по медиане “rating” = репутация в десятичном виде

get_active_witnesses()

get_all_accounts()

get_block(n)

get_chain_properties()

get_config()

get_content(url, **kwargs)

get_curation_percent()

get_current_median_history_price()

get_database_info()

get_dynamic_global_properties()

get_feed_history()

get_follow(account)

get_key_references(public_key)

Позволяет узнать какому логину соответсвует публичный ключ #public_key = ‘GLS6RGi692mJSNkdcVRunY3tGieJdTsa7AZeBVjB6jjqYg98ov5NL’ Но не позволяет если есть авторити у аккаунта

get_market_history_buckets()

get_median_price()

get_open_orders(account)

get_ops_in_block(n)

get_order_book(limit)

get_order_book_extended(limit)

get_order_price()

get_recent_trades(limit)

get_ticker()

try:

get_tickers()

get_volume()

get_witness_by_account(account)

get_witness_count()

get_witness_schedule()

is_login(login)

lookup_witness_accounts(start, limit)

post(title, body, author, wif, **kwargs)

category = ‘’ url = ‘’ permlink = ‘’ tags = []

replace(title, body, author, wif, **kwargs)

repost(url, account, wif, **kwargs)

resolve_url(url)

transfer(to, amount, from_account, wif[, …])

Transfer amount coins (of asset) to from_account using the private key wif and the memo memo

transfer_to_vesting(to, amount, …)

Power up a given amount of DEFAULT_ASSET (default: GOLOS) from from_account into to.

transfers(raw_ops, from_account, wif)

Execute multiple transfers in a single transaction.

vote(url, weight, voters, wif)

withdraw_vesting(account, amount, wif, **kwargs)

find_op_transaction(op: dict, ignore_keys: list = None) → dict[source]

Locate and return the full transaction from the blockchain based on a dict operation (op)

The operation dictionary must contain at least block, as well as all of the operation keys that would be found on the blockchain, with the values being the same type as they would be on the blockchain.

Example usage:

>>> op = {'from':  'someguy123', 'to': 'ksantoprotein', 'amount': '0.100 GOLOS', 'memo': 'testing',
...       'number': 127287, 'block': 30895436, 'timestamp': '2019-10-01T12:49:00', 'type_op': 'transfer'}
>>> Api().find_op_transaction(op)
{'ref_block_num': 27979, 'ref_block_prefix': 3018856747, 'expiration': '2019-10-01T12:50:00',
 'operations': [['transfer',
    {'from': 'someguy123', 'to': 'ksantoprotein', 'amount': '0.100 GOLOS', 'memo': 'testing'}
  ]],
  'extensions': [],
  'signatures': ['1f1a0212f7b9fe263acaeadf1ec127000dc234c413b543e3c268d251e...']
}
Parameters
  • op (dict) – An operation as a dict, containing the key block, and any operation keys to match

  • ignore_keys (list) – (Optional) Additional dict keys to remove from op

Raises

TransactionNotFound – When a matching transaction could not be found on the blockchain.

Return dict tx

The full transaction found on the blockchain as a dict

A returned transaction is generally formatted like such:

dict(ref_block_num: int, ref_block_prefix: int, expiration: str, operations: list,
     extensions: list, signatures: list)
get_accounts(logins: List[str], **kwargs) → List[dict][source]

Перерасчитываются некоторые параметры по аккаунту “voting_power” - 1..10000 реальная батарейка “golos_power” - сила голоса с учетом делегирования “rshares” - сколько добавится шаров в пост при 100% батарейке “GOLOS”, “GBG” - ликвидные токены “new_post_limit” - сколько постов можно опубликовать “new_post_time” - сколько осталось времени в минутах до публикации без штрафа “bandwidth” = {

“avail” - всего доступно в кБ “used_forum” - использовано в кБ “used_market” - использовано в кБ “free_forum” - доступно в кБ “free_market” - доступно в кБ }

“value” = {“GOLOS”, “GBG”} - цена апвота по внутренней бирже “order” = {“GOLOS”, “GBG”} - цена апвота по медиане “rating” = репутация в десятичном виде

get_key_references(public_key: str)[source]

Позволяет узнать какому логину соответсвует публичный ключ #public_key = ‘GLS6RGi692mJSNkdcVRunY3tGieJdTsa7AZeBVjB6jjqYg98ov5NL’ Но не позволяет если есть авторити у аккаунта

get_ticker()[source]
try:

t = {“bid”: round(float(ticker[“highest_bid”]), 6), “ask”: round(float(ticker[“lowest_ask”]), 6)}

except:

return False

get_transaction(txid: str) → dict[source]

Lookup the transaction ID txid and return it’s matching transaction as a dict

Example usage:

>>> Api().get_transaction('c901c52daf57b60242d9d7be67f790e023cf2780')
{'ref_block_num': 27979, 'ref_block_prefix': 3018856747, 'expiration': '2019-10-01T12:50:00',
 'operations': [['transfer',
    {'from': 'someguy123', 'to': 'ksantoprotein', 'amount': '0.100 GOLOS', 'memo': 'testing'}
  ]],
  'extensions': [],
  'signatures': ['1f1a0212f7b9fe263acaeadf1ec127000dc234c413b543e3c268d251e...']
}
Parameters

txid (str) – A string hex transaction ID to lookup

Raises

TransactionNotFound – When the transaction ID could not be found on the blockchain.

Return dict tx

The matching transaction as a dict

get_transaction_hex(tx: dict, remove_sigs=False) → str[source]

Get the string hexadecimal representation of a dict transaction object.

Example Usage:

>>> tx = {
...     'ref_block_num': 27979, 'ref_block_prefix': 3018856747, 'expiration': '2019-10-01T12:50:00',
...     'operations': [
...         ['transfer',
...          {'from': 'someguy123', 'to': 'ksantoprotein', 'amount': '0.100 GOLOS', 'memo': 'testing'}]
...     ],
...     'extensions': [], 'signatures': []
... }
>>> Api().get_transaction_hex(tx)
'4b6d2b19f0b3784b935d01020a736f6d656775793132330d6b73616e746f70726f7465696e640000000000000003474f4c4f53
 00000774657374696e6700'
Parameters
  • tx (dict) – A transaction as a dict in the form: dict(ref_block_num, ref_block_prefix, expiration, operations, extensions, signatures)

  • remove_sigs (bool) – (Default: False) Replace the signatures key with [] (for TXID generation)

Return str txhex

The hexadecimal representation of the transaction

get_transaction_id(tx: dict) → str[source]

Calculate the TXID for a transaction in the dict form:

dict(ref_block_num, ref_block_prefix, expiration, operations, extensions, signatures)

>>> tx = {
...     'ref_block_num': 27979, 'ref_block_prefix': 3018856747, 'expiration': '2019-10-01T12:50:00',
...     'operations': [
...         ['transfer',
...          {'from': 'someguy123', 'to': 'ksantoprotein', 'amount': '0.100 GOLOS', 'memo': 'testing'}]
...     ],
...     'extensions': [], 'signatures': []
... }
>>> Api().get_transaction_id(tx)
'c901c52daf57b60242d9d7be67f790e023cf2780'
Parameters

tx (dict) – A transaction as a dict in the form: dict(ref_block_num, ref_block_prefix, expiration, operations, extensions, signatures)

Return str txid

The calculated transaction ID for the given transaction

post(title, body, author, wif, **kwargs)[source]

category = ‘’ url = ‘’ permlink = ‘’ tags = []

beneficiaries = ‘login:10000’ weight = 10000 curation = max or int 2500..10000

transfer(to: str, amount: Union[decimal.Decimal, float, int, str], from_account: str, wif: str, asset='GOLOS', memo='', **kwargs)[source]

Transfer amount coins (of asset) to from_account using the private key wif and the memo memo

Basic usage:

>>> g = Api()
>>> tf = golos.transfer(
...     to='ksantoprotein', amount='0.1', asset='GOLOS', from_account='someguy123',
...     wif='5Jq19TeeVmGrBFnu32oxfxQMiipnSCKmwW7fZGUVLAoqsKJ9JwP', memo='this is an example transfer'
... )
>>> print('TXID:', tf['id'], 'Block:', tf['block_num'])
TXID: c901c52daf57b60242d9d7be67f790e023cf2780 Block: 30895436
Parameters
  • to (str) – The username of the account you want to send coins to

  • amount (Decimal) – The amount of coins to send, as either a Decimal, str, int or float

  • from_account (str) – The username of the account to send from

  • wif (str) – The active/owner private key for the from_account, as a string in WIF format

  • asset (str) – The asset (coin) to send (Default: GOLOS (value of DEFAULT_ASSET))

  • memo (str) – An optional public message to attach to the transfer (Default: '' - empty string)

  • kwargs – Any additional keyword arguments

Return dict transfer

A dictionary containing info about the completed transfer, inc. id (full ret below)

Return data:

dict(
    ref_block_num: int, ref_block_prefix:int,
    expiration:str, operations:list, extensions:list,
    signatures:List[str], block_num:int, id:str
)
transfer_to_vesting(to: str, amount: Union[decimal.Decimal, float, int, str], from_account: str, wif: str, **kwargs)[source]

Power up a given amount of DEFAULT_ASSET (default: GOLOS) from from_account into to.

Basic Usage (Convert 1000 GOLOS from someguy123 into GESTS to someguy123)

>>> g = Api()
>>> tf = g.transfer_to_vesting(
...   to='someguy123', from_account='someguy123', wif='5Jq19TeeVmGrBFnu32oxfxQMiipnSCKmwW7fZGUVLAoqsKJ9JwP'
...   amount='1000'
... )
>>> print('TXID:', tf['id'], 'Block:', tf['block_num'])
TXID: c901c52daf57b60242d9d7be67f790e023cf2780 Block: 30895436
Parameters
  • to (str) – The username of the account you want to send coins to

  • amount (Decimal) – The amount of coins to send, as either a Decimal, str, int or float

  • from_account (str) – The username of the account to send from

  • wif (str) – The active/owner private key for the from_account, as a string in WIF format

Return dict transfer

A dictionary containing info about the completed TX, inc. id (full ret below)

Return data:

dict(
    ref_block_num: int, ref_block_prefix:int,
    expiration:str, operations:list, extensions:list,
    signatures:List[str], block_num:int, id:str
)
transfers(raw_ops: List[Tuple[str, Union[decimal.Decimal, float, int, str], str, str]], from_account: str, wif: str)[source]

Execute multiple transfers in a single transaction.

>>> tfrs = [('john', '1.234', 'GOLOS', 'thanks man'), ('dave', '0.374', 'GBG', 'hi dave'), ]
>>> g = Api()
>>> tf = g.transfers(raw_ops=tfrs, from_account='someguy123',
...                  wif='5Jq19TeeVmGrBFnu32oxfxQMiipnSCKmwW7fZGUVLAoqsKJ9JwP')
>>> print('TXID:', tf['id'], 'Block:', tf['block_num'])
TXID: c901c52daf57b60242d9d7be67f790e023cf2780 Block: 30895436
Parameters
  • raw_ops (List[Tuple]) – A list of transfers as 4 key tuples: (to:str, amount:str, asset:str, memo:str)

  • from_account (str) – The username of the account to send from

  • wif (str) – The active/owner private key for the from_account, as a string in WIF format

Return dict transfer

A dictionary containing info about the completed TX, inc. id (full ret below)

Return data:

dict(
    ref_block_num: int, ref_block_prefix:int,
    expiration:str, operations:list, extensions:list,
    signatures:List[str], block_num:int, id:str
)