bitcoinlib.services.services module

class bitcoinlib.services.services.Service(network='bitcoin', min_providers=1, max_providers=1, providers=None)[source]

Bases: object

Class to connect to various cryptocurrency service providers. Use to receive network and blockchain information, get specific transaction information, current network fees or push a raw transaction.

The Service class connects to 1 or more service providers at random to retrieve or send information. When a certain service provider fail it automatically tries another one.

Open a service object for the specified network. By default the object connect to 1 service provider, but you can specify a list of providers or a minimum or maximum number of providers.

Parameters:
  • network (str, Network) – Specify network used
  • min_providers – Minimum number of providers to connect to. Default is 1. Use for instance to receive

fee information from a number of providers and calculate the average fee. :type min_providers: int :param max_providers: Maximum number of providers to connect to. Default is 1. :type max_providers: int :param providers: List of providers to connect to. Default is all providers and select a provider at random. :type providers: list, str

block_count()[source]

Get latest block number: The block number of last block in longest chain on the blockchain

Return int:
estimatefee(blocks=3)[source]

Estimate fee per kilobyte for a transaction for this network with expected confirmation within a certain amount of blocks

Parameters:blocks (int) – Expection confirmation time in blocks. Default is 3.
Return int:Fee in smallest network denominator (satoshi)
getbalance(addresslist, addresses_per_request=5)[source]

Get balance for each address in addresslist provided

Parameters:
  • addresslist (list, str) – Address or list of addresses
  • addresses_per_request (int) – Maximum number of addresses per request. Default is 5. Use lower setting when you experience timeouts or service request errors, or higher when possible.
Return dict:

Balance per address

getrawtransaction(txid)[source]

Get a raw transaction by its transaction hash

Parameters:txid (str, bytes) – Transaction identification hash
Return str:Raw transaction as hexstring
gettransaction(txid)[source]

Get a transaction by its transaction hash

Parameters:txid (str, bytes) – Transaction identification hash
Return Transaction:
 A single transaction object
gettransactions(addresslist, addresses_per_request=5)[source]

Get all transactions for each address in addresslist

Parameters:
  • addresslist (list, str) – Address or list of addresses
  • addresses_per_request (int) – Maximum number of addresses per request. Default is 5. Use lower setting when you experience timeouts or service request errors, or higher when possible.
Return list:

List of Transaction objects

getutxos(addresslist, addresses_per_request=5)[source]

Get list of unspent outputs (UTXO’s) per address

Parameters:
  • addresslist (list, str) – Address or list of addresses
  • addresses_per_request (int) – Maximum number of addresses per request. Default is 5. Use lower setting when you experience timeouts or service request errors, or higher when possible.
Return dict:

UTXO’s per address

sendrawtransaction(rawtx)[source]

Push a raw transaction to the network

Parameters:rawtx (str, bytes) – Raw transaction as hexstring
Return dict:Send transaction result
exception bitcoinlib.services.services.ServiceError(msg='')[source]

Bases: Exception