Code

transactions module

class transactions.Transactions(service=u'blockr', testnet=False, username=u'', password=u'', host=u'', port=u'')

Transactions: Bitcoin for Humans

All amounts are in satoshi

__init__(service=u'blockr', testnet=False, username=u'', password=u'', host=u'', port=u'')
Parameters:
  • service (str) – currently supports _blockr_ for blockr.io and and _daemon_ for bitcoin daemon. Defaults to _blockr_
  • testnet (bool) – use True if you want to use tesnet. Defaults to False
  • username (str) – username to connect to the bitcoin daemon
  • password (str) – password to connect to the bitcoin daemon
  • hosti (str) – host of the bitcoin daemon
  • port (str) – port of the bitcoin daemon
build_transaction(inputs, outputs)

Thin wrapper around bitcoin.mktx(inputs, outputs)

Parameters:
  • inputs (dict) – inputs in the form of {'output': 'txid:vout', 'value': amount in satoshi}
  • outputs (dict) – outputs in the form of {'address': to_address, 'value': amount in satoshi}
Returns:

transaction

get(hash, account=u'*', max_transactions=100, min_confirmations=6, raw=False)
Parameters:
  • hash – can be a bitcoin address or a transaction id. If it’s a bitcoin address it will return a list of transactions up to max_transactions a list of unspents with confirmed transactions greater or equal to min_confirmantions
  • account (Optional[str]) – used when using the bitcoind. bitcoind does not provide an easy way to retrieve transactions for a single address. By using account we can retrieve transactions for addresses in a specific account
Returns:

transaction

push(tx)
Parameters:tx – hex of signed transaction
Returns:pushed transaction
sign_transaction(tx, master_password, path=u'')
Parameters:
  • tx – hex transaction to sign
  • master_password – master password for BIP32 wallets. Can be either a master_secret or a wif
  • path (Optional[str]) – optional path to the leaf address of the BIP32 wallet. This allows us to retrieve private key for the leaf address if one was used to construct the transaction.
Returns:

signed transaction

Note

Only BIP32 hierarchical deterministic wallets are currently supported.

simple_transaction(from_address, to, op_return=None, min_confirmations=6)
Parameters:
  • from_address (str) – bitcoin address originating the transaction
  • to – tuple of (to_address, amount) or list of tuples [(to_addr1, amount1), (to_addr2, amount2)]. Amounts are in satoshi
  • op_return (str) – ability to set custom op_return
  • min_confirmations (int) – minimal number of required confirmations
Returns:

transaction

service module

Defines the main BitcoinService class which other services should subclass.

class transactions.services.service.BitcoinService(testnet=False)
_min_dust

int

Minimum tx accepted by blockr.io. Defaults to``3000``.

maxTransactionFee

int

Maximum transaction fee. Defaults to 50000.

_min_transaction_fee

int

Minimum mining fee. Defaults to 30000.

Todo

Give a bit more explanations about each attribute.

__init__(testnet=False)
Parameters:testnet (bool) – Set to True to use the testnet. Defaults to False, meaning that the mainnet will be used.