bhive.hiveconnect module

class bhive.hiveconnect.HiveConnect(hive_instance=None, *args, **kwargs)

Bases: object

Parameters

scope (str) – comma separated string with scopes login,offline,vote,comment,delete_comment,comment_options,custom_json,claim_reward_balance

# Run the login_app in examples and login with a account
from bhive import Hive
from bhive.hiveconnect import HiveConnect
from bhive.comment import Comment
sc2 = HiveConnect(client_id="bhive.app")
hive = Hive(hiveconnect=sc2)
hive.wallet.unlock("supersecret-passphrase")
post = Comment("author/permlink", hive_instance=hive)
post.upvote(voter="test")  # replace "test" with your account

Examples for creating hiveconnect v2 urls for broadcasting in browser:

from bhive import Hive
from bhive.account import Account
from bhive.hiveconnect import HiveConnect
from pprint import pprint
hive = Hive(nobroadcast=True, unsigned=True)
sc2 = HiveConnect(hive_instance=hive)
acc = Account("test", hive_instance=hive)
pprint(sc2.url_from_tx(acc.transfer("test1", 1, "HIVE", "test")))
'https://hiveconnect.com/sign/transfer?from=test&to=test1&amount=1.000+HIVE&memo=test'
from bhive import Hive
from bhive.transactionbuilder import TransactionBuilder
from bhivebase import operations
from bhive.hiveconnect import HiveConnect
from pprint import pprint
hv = Hive(nobroadcast=True, unsigned=True)
sc2 = HiveConnect(hive_instance=hv)
tx = TransactionBuilder(hive_instance=hv)
op = operations.Transfer(**{"from": 'test',
                            "to": 'test1',
                            "amount": '1.000 HIVE',
                            "memo": 'test'})
tx.appendOps(op)
pprint(sc2.url_from_tx(tx.json()))
'https://hiveconnect.com/sign/transfer?from=test&to=test1&amount=1.000+HIVE&memo=test'
broadcast(operations, username=None)

Broadcast an operation

Sample operations:

[
    [
        'vote', {
                    'voter': 'gandalf',
                    'author': 'gtg',
                    'permlink': 'hive-pressure-4-need-for-speed',
                    'weight': 10000
                }
    ]
]
create_hot_sign_url(operation, params, redirect_uri=None)

Creates a link for broadcasting an operation

Parameters
  • operation (str) – operation name (e.g.: vote)

  • params (dict) – operation dict params

  • redirect_uri (str) – Redirects to this uri, when set

get_access_token(code)
get_login_url(redirect_uri, **kwargs)

Returns a login url for receiving token from hiveconnect

property headers
me(username=None)

Calls the me function from hiveconnect

from bhive.hiveconnect import HiveConnect
sc2 = HiveConnect()
sc2.hive.wallet.unlock("supersecret-passphrase")
sc2.me(username="test")
refresh_access_token(code, scope)
revoke_token(access_token)
set_access_token(access_token)

Is needed for broadcast() and me()

set_username(username, permission='posting')

Set a username for the next broadcast() or me() operation. The necessary token is fetched from the wallet

update_user_metadata(metadata)
url_from_tx(tx, redirect_uri=None)

Creates a link for broadcasting an operation

Parameters
  • tx (dict) – includes the operation, which should be broadcast

  • redirect_uri (str) – Redirects to this uri, when set