Api¶
-
class
golos.api.
Api
(nodes: Union[List[str], str] = None, **kwargs)[source]¶ Main class for
golos-python
- wrapsws_client
and provides many helper methods for interacting with the GOLOS blockchain, such asget_accounts()
andtransfer()
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'
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, …)find_op_transaction
(op[, ignore_keys])Locate and return the full transaction from the blockchain based on a
dict
operation (op
)follow
(wtf, followings, followers, wif, **kwargs)get_account_history
(account[, op_limit])Get the account history for a given
account
as aList[dict]
.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_balances
(*accounts)Get all balances for one or more
accounts
(as positional arguments).get_block
(n)- return dict props
A dictionary of chain properties, containing:
get_content
(url, **kwargs)- return dict dynamic_props
A dictionary containing the dynamic global properties (see below)
get_follow
(account)get_key_references
(public_key)Позволяет узнать какому логину соответсвует публичный ключ #public_key = ‘GLS6RGi692mJSNkdcVRunY3tGieJdTsa7AZeBVjB6jjqYg98ov5NL’ Но не позволяет если есть авторити у аккаунта
get_open_orders
(account)get_order_book
(limit)get_order_book_extended
(limit)get_recent_trades
(limit)try:
get_transaction
(txid)Lookup the transaction ID
txid
and return it’s matching transaction as adict
get_transaction_hex
(tx[, remove_sigs])Get the string hexadecimal representation of a
dict
transaction object.Calculate the TXID for a transaction in the
dict
form:get_witness_by_account
(account)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 (ofasset
) tofrom_account
using the private keywif
and the memomemo
transfer_to_vesting
(to, amount, …)Power up a given amount of
DEFAULT_ASSET
(default:GOLOS
) fromfrom_account
intoto
.transfers
(raw_ops, from_account, wif)Execute multiple transfers in a single transaction.
vests_to_power
(vests)Basic Usage.
vote
(url, weight, voters, wif)withdraw_vesting
(account, amount, wif, **kwargs)Attributes
This property loads and caches the chain properties for up to 30 seconds, avoiding constant un-necessary requests for the chain properties.
This property loads and caches the dynamic global properties for up to 30 seconds, avoiding constant un-necessary requests for the dynamic global properties.
-
property
chain_properties
¶ This property loads and caches the chain properties for up to 30 seconds, avoiding constant un-necessary requests for the chain properties.
- Return dict props
A dictionary of chain properties
-
property
dynamic_global_properties
¶ This property loads and caches the dynamic global properties for up to 30 seconds, avoiding constant un-necessary requests for the dynamic global properties.
- Return dict props
A dictionary of dynamic global properties
-
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
- 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_account_history
(account: str, op_limit: Union[list, str] = 'all', **kwargs) → List[dict][source]¶ Get the account history for a given
account
as aList[dict]
.Optionally you can filter the operations returned using
op_limit
, as well as limit the number of operations withstart_limit
, and maximum operation age withage
.Basic usage:
>>> g = Api() >>> # Return a list of 'transfer' operations for the account 'someguy123' >>> hist = g.get_account_history('someguy123', op_limit='transfer') >>> h[0] {'from': 'someguy123', 'to': 'someguy123', 'amount': '0.100 GOLOS', 'memo': 'testing', 'number': 127290, 'block': 30908474, 'timestamp': '2019-10-01T23:41:18', 'type_op': 'transfer', 'trx_id': '80c7e0f7444f63074a52a8ba44cf066551706588'}
- Parameters
- Key int start_limit
Load at most this many history items (Default:
1000
items)- Key int age
Skip history items older than this many seconds (Default:
604800
seconds / 7 days)- Return List[dict] history
A
list
ofdict
history ops (see below for format)
dict(from, to, amount: str, memo, number, block, timestamp: str, type_op, trx_id)
-
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_balances
(*accounts) → Dict[str, Dict[str, decimal.Decimal]][source]¶ Get all balances for one or more
accounts
(as positional arguments).Basic Usage:
>>> b = Api().get_balances('john', 'dave') >>> b['john']['GOLOS'] Decimal('4183.323') >>> b['dave']['GBG'] Decimal('837.978')
- Parameters
accounts (str) – One or more usernames to get balances for
- Return dict balances
A dict of
{account: {asset: balance, ..}, ..}
, for example:
{ 'someguy123': { 'GOLOS': Decimal('157560.131'), 'GBG': Decimal('6420.916'), 'GP': Decimal('15044.951'), 'GESTS': Decimal('50058788.632180') } }
-
get_chain_properties
() → dict[source]¶ - Return dict props
A dictionary of chain properties, containing:
dict(account_creation_fee, maximum_block_size, sbd_interest_rate, create_account_min_golos_fee, create_account_min_delegation, create_account_delegation_time, min_delegation, max_referral_interest_rate, max_referral_term_sec, min_referral_break_fee, max_referral_break_fee, posts_window, posts_per_window, comments_window, comments_per_window, votes_window, votes_per_window, auction_window_size, max_delegated_vesting_interest_rate, custom_ops_bandwidth_multiplier, min_curation_percent, max_curation_percent, curation_reward_curve, allow_distribute_auction_reward, allow_return_auction_reward_to_fund)
-
get_dynamic_global_properties
() → Union[bool, dict][source]¶ - Return dict dynamic_props
A dictionary containing the dynamic global properties (see below)
dict( id, head_block_number, head_block_id, time, current_witness, total_pow, num_pow_witnesses, virtual_supply, current_supply, confidential_supply, current_sbd_supply, confidential_sbd_supply, sbd_interest_rate, sbd_print_rate, average_block_size, maximum_block_size, current_aslot, recent_slots_filled, participation_count, max_virtual_bandwidth, current_reserve_ratio, custom_ops_bandwidth_multiplier, is_forced_min_price, transit_block_num, transit_witnesses, total_vesting_fund_steem, total_reward_fund_steem, total_vesting_shares, total_reward_shares2, last_irreversible_block_num, vote_regeneration_per_day, golos_per_vests, now )
-
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 adict
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
- 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 (ofasset
) tofrom_account
using the private keywif
and the memomemo
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
orfloat
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 formatasset (str) – The asset (coin) to send (Default:
GOLOS
(value ofDEFAULT_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
) fromfrom_account
intoto
.Basic Usage (Convert 1000 GOLOS from
someguy123
into GESTS tosomeguy123
)>>> 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
orfloat
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
- 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 )
-
vests_to_power
(vests: Union[decimal.Decimal, float, int, str]) → decimal.Decimal[source]¶ Basic Usage:
>>> Api().vests_to_power('50058788') # Convert ``50058788 GESTS`` into ``GOLOS`` Decimal('15043.793')
- Parameters
vests (Number) – An amount in VESTS/GESTS to convert to SP / GP
- Return Decimal power
The value of the VESTS / GESTS in STEEM / GOLOS
-