helium-py: Official Helium Library

Release v0.2a2. (Installation)

Requests Downloads Per Month Badge License Badge Wheel Support Badge Python Version Support Badge

helium-py is the official Python library for interacting with the Helium blockchain.

Check out the Quickstart section to get started.

Note

Prior to 1.0.0 this project does not guarantee a stable public API.


Installation

To use helium-py, first install it using pip:

$ pip install helium-py

Usage

The following examples demonstrate some of the more common use cases and show how these packages can be used in combination to accomplish common tasks.

Creating and submitting a payment transaction

A payment from an owned keypair initialized with a 12 word mnemonic to an address specified by its base58 representation. The transaction is serialized to binary and submitted to the blockchain API.

 1import logging
 2
 3from helium_py.crypto.keypair import Address, Keypair
 4from helium_py.transactions import Payment, PaymentV2
 5from helium_py.api import Accounts, PendingTransactions, Transactions
 6
 7logger = logging.getLogger(__name__)
 8
 9# Initialize an owned keypair from a 12 word mnemonic
10bob = Keypair.from_words(['one', 'two', ..., 'twelve'])
11
12# Initialize an address from a b58 string
13alice = Address.from_b58(b'148d8KTRcKA5JKP ekBcKFd4KfvprvFRpjGtivhtmRmnZ8MFYnP3')
14
15# get the speculative nonce for the keypair
16account = Accounts().account_for_address(bob.address.b58.decode())
17
18payment_transaction = PaymentV2(
19    payer=bob,
20    payments=[
21        Payment(
22            payee=alice,
23            amount=10,
24            memo=b'memo',
25        ),
26    ],
27    nonce=account['speculative_nonce'] + 1,
28)
29
30# an appropriate transaction fee is calculated at initialization
31logger.info(f'transaction fee is: {payment_transaction.calculated_fee}')
32
33# sign the payment txn with bob's keypair
34signed_payment_transaction = payment_transaction.sign(payer=bob)
35
36# submit the serialized txn to the Blockchain HTTP API
37pending_transactions_client = PendingTransactions()
38response_dict = pending_transactions_client.submit_transaction(signed_payment_transaction)
39
40# check on status of pending transaction
41pending_transactions_client.get_status(response_dict['hash'])
42
43# view finalized transaction information
44transaction_dict = Transactions().get_transaction(response_dict['hash'])