Developer Interface

Keys

bit.Key

alias of bit.wallet.PrivateKey

class bit.PrivateKey(wif=None)

This class represents a Bitcoin private key. Key is an alias.

Parameters

wif (str) – A private key serialized to the Wallet Import Format. If the argument is not supplied, a new private key will be created. The WIF compression flag will be adhered to, but the version byte is disregarded. Compression will be used by all new keys.

Raises

TypeError – If wif is not a str.

property address

The public address you share with others to receive funds.

balance_as(currency)

Returns your balance as a formatted string in a particular currency.

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

can_sign_unspent(unspent)
create_transaction(outputs, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Creates a signed P2PKH transaction.

Parameters
  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • fee (int) – The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.earn.com and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

The signed transaction as hex.

Return type

str

classmethod from_bytes(bytestr)
Parameters

bytestr (bytes) – A private key previously encoded as hex.

Return type

PrivateKey

classmethod from_der(der)
Parameters

der (bytes) – A private key previously encoded as DER.

Return type

PrivateKey

classmethod from_hex(hexed)
Parameters

hexed (str) – A private key previously encoded as hex.

Return type

PrivateKey

classmethod from_int(num)
Parameters

num (int) – A private key in raw integer form.

Return type

PrivateKey

classmethod from_pem(pem)
Parameters

pem (bytes) – A private key previously encoded as PEM.

Return type

PrivateKey

get_balance(currency='satoshi')

Fetches the current balance by calling get_unspents() and returns it using balance_as().

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

get_transactions()

Fetches transaction history.

Return type

list of str transaction IDs

get_unspents()

Fetches all available unspent transaction outputs.

Return type

list of Unspent

is_compressed()

Returns whether or not this private key corresponds to a compressed public key.

Return type

bool

classmethod prepare_transaction(address, outputs, compressed=True, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Prepares a P2PKH transaction for offline signing.

Parameters
  • address (str) – The address the funds will be sent from.

  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • compressed (bool) – Whether or not the address corresponds to a compressed public key. This influences the fee.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.earn.com and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

JSON storing data required to create an offline transaction.

Return type

str

pub_to_hex()
Return type

str

property public_key

The public point serialized to bytes.

property public_point

The public point (x, y).

property scriptcode
property segwit_address

The public segwit nested in P2SH address you share with others to receive funds.

property segwit_scriptcode
send(outputs, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Creates a signed P2PKH transaction and attempts to broadcast it on the blockchain. This accepts the same arguments as create_transaction().

Parameters
  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.earn.com and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

The transaction ID.

Return type

str

sign(data)

Signs some data which can be verified later by others using the public key.

Parameters

data (bytes) – The message to sign.

Returns

A signature compliant with BIP-62.

Return type

bytes

sign_transaction(tx_data, unspents=None)

Creates a signed P2PKH transaction using previously prepared transaction data.

Parameters
  • tx_data (str) – Hex-encoded transaction or output of prepare_transaction().

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

Returns

The signed transaction as hex.

Return type

str

to_bytes()
Return type

bytes

to_der()
Return type

bytes

to_hex()
Return type

str

to_int()
Return type

int

to_pem()
Return type

bytes

to_wif()
verify(signature, data)

Verifies some data was signed by this private key.

Parameters
  • signature (bytes) – The signature to verify.

  • data (bytes) – The data that was supposedly signed.

Return type

bool

class bit.PrivateKeyTestnet(wif=None)

This class represents a testnet Bitcoin private key. Note: coins on the test network have no monetary value!

Parameters

wif (str) – A private key serialized to the Wallet Import Format. If the argument is not supplied, a new private key will be created. The WIF compression flag will be adhered to, but the version byte is disregarded. Compression will be used by all new keys.

Raises

TypeError – If wif is not a str.

property address

The public address you share with others to receive funds.

balance_as(currency)

Returns your balance as a formatted string in a particular currency.

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

can_sign_unspent(unspent)
create_transaction(outputs, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Creates a signed P2PKH transaction.

Parameters
  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.earn.com and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the testnet blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

The signed transaction as hex.

Return type

str

classmethod from_bytes(bytestr)
Parameters

bytestr (bytes) – A private key previously encoded as hex.

Return type

PrivateKeyTestnet

classmethod from_der(der)
Parameters

der (bytes) – A private key previously encoded as DER.

Return type

PrivateKeyTestnet

classmethod from_hex(hexed)
Parameters

hexed (str) – A private key previously encoded as hex.

Return type

PrivateKeyTestnet

classmethod from_int(num)
Parameters

num (int) – A private key in raw integer form.

Return type

PrivateKeyTestnet

classmethod from_pem(pem)
Parameters

pem (bytes) – A private key previously encoded as PEM.

Return type

PrivateKeyTestnet

get_balance(currency='satoshi')

Fetches the current balance by calling get_unspents() and returns it using balance_as().

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

get_transactions()

Fetches transaction history.

Return type

list of str transaction IDs

get_unspents()

Fetches all available unspent transaction outputs.

Return type

list of Unspent

is_compressed()

Returns whether or not this private key corresponds to a compressed public key.

Return type

bool

classmethod prepare_transaction(address, outputs, compressed=True, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Prepares a P2PKH transaction for offline signing.

Parameters
  • address (str) – The address the funds will be sent from.

  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • compressed (bool) – Whether or not the address corresponds to a compressed public key. This influences the fee.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.earn.com and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

JSON storing data required to create an offline transaction.

Return type

str

pub_to_hex()
Return type

str

property public_key

The public point serialized to bytes.

property public_point

The public point (x, y).

property scriptcode
property segwit_address

The public segwit nested in P2SH address you share with others to receive funds.

property segwit_scriptcode
send(outputs, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Creates a signed P2PKH transaction and attempts to broadcast it on the testnet blockchain. This accepts the same arguments as create_transaction().

Parameters
  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.earn.com and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the testnet blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

The transaction ID.

Return type

str

sign(data)

Signs some data which can be verified later by others using the public key.

Parameters

data (bytes) – The message to sign.

Returns

A signature compliant with BIP-62.

Return type

bytes

sign_transaction(tx_data, unspents=None)

Creates a signed P2PKH transaction using previously prepared transaction data.

Parameters
  • tx_data (str) – Hex-encoded transaction or output of prepare_transaction().

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

Returns

The signed transaction as hex.

Return type

str

to_bytes()
Return type

bytes

to_der()
Return type

bytes

to_hex()
Return type

str

to_int()
Return type

int

to_pem()
Return type

bytes

to_wif()
verify(signature, data)

Verifies some data was signed by this private key.

Parameters
  • signature (bytes) – The signature to verify.

  • data (bytes) – The data that was supposedly signed.

Return type

bool

class bit.MultiSig(private_key, public_keys, m)

This class represents a Bitcoin multisignature contract. Note: coins on the test network have no monetary value!

Parameters
  • private_key (PrivateKey) – A class representing a private key.

  • public_keys (list or set of str or bytes) – A list or set of public keys encoded as hex or bytes assigned to the multi-signature contract. If using a list, then the order of the public keys will be used in the contract. If using a set, then Bit will order the public keys according to lexicographical order.

  • m (int) – The number of required signatures to spend from this multi- signature contract.

Raises
  • TypeError – If private_key is not a PrivateKey.

  • TypeError – When the list public_keys does not include the public key corresponding to the private key used in this class.

property address

The public address you share with others to receive funds.

balance_as(currency)

Returns your balance as a formatted string in a particular currency.

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

can_sign_unspent(unspent)
create_transaction(outputs, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Creates a signed P2SH transaction.

Parameters
  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • fee (int) – The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.21.co and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the testnet blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

The signed transaction as hex.

Return type

str

get_balance(currency='satoshi')

Fetches the current balance by calling get_unspents() and returns it using balance_as().

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

get_transactions()

Fetches transaction history.

Return type

list of str transaction IDs

get_unspents()

Fetches all available unspent transaction outputs.

Return type

list of Unspent

classmethod prepare_transaction(address, outputs, compressed=True, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Prepares a P2SH transaction for offline signing.

Parameters
  • address (str) – The address the funds will be sent from.

  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • compressed (bool) – Whether or not the address corresponds to a compressed public key. This influences the fee.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.21.co and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

JSON storing data required to create an offline transaction.

Return type

str

property scriptcode
property segwit_address

The public segwit nested in P2SH address you share with others to receive funds.

property segwit_scriptcode
sign(data)

Signs some data which can be verified later by others using the public key.

Parameters

data (bytes) – The message to sign.

Returns

A signature compliant with BIP-62.

Return type

bytes

sign_transaction(tx_data, unspents=None)

Creates a signed P2SH transaction using previously prepared transaction data.

Parameters
  • tx_data (str) – Hex-encoded transaction or output of prepare_transaction().

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

Returns

The signed transaction as hex.

Return type

str

class bit.MultiSigTestnet(private_key, public_keys, m)

This class represents a testnet Bitcoin multisignature contract. Note: coins on the test network have no monetary value!

Parameters
  • private_key (PrivateKeyTestnet) – A class representing a testnet private key.

  • public_keys (list or set of str or bytes) – A list or set of public keys encoded as hex or bytes assigned to the multi-signature contract. If using a list, then the order of the public keys will be used in the contract. If using a set, then Bit will order the public keys according to lexicographical order.

  • m (int) – The number of required signatures to spend from this multi- signature contract.

Raises
  • TypeError – If private_key is not a PrivateKeyTestnet.

  • TypeError – When the list public_keys does not include the public key corresponding to the private key used in this class.

property address

The public address you share with others to receive funds.

balance_as(currency)

Returns your balance as a formatted string in a particular currency.

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

can_sign_unspent(unspent)
create_transaction(outputs, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Creates a signed P2SH transaction.

Parameters
  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.21.co and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the testnet blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

The signed transaction as hex.

Return type

str

get_balance(currency='satoshi')

Fetches the current balance by calling get_unspents() and returns it using balance_as().

Parameters

currency (str) – One of the Supported Currencies.

Return type

str

get_transactions()

Fetches transaction history.

Return type

list of str transaction IDs

get_unspents()

Fetches all available unspent transaction outputs.

Return type

list of Unspent

classmethod prepare_transaction(address, outputs, compressed=True, fee=None, absolute_fee=False, leftover=None, combine=True, message=None, unspents=None, message_is_hex=False, replace_by_fee=False)

Prepares a P2SH transaction for offline signing.

Parameters
  • address (str) – The address the funds will be sent from.

  • outputs (list of tuple) – A sequence of outputs you wish to send in the form (destination, amount, currency). The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. The currency must be supported.

  • compressed (bool) – Whether or not the address corresponds to a compressed public key. This influences the fee.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bit will poll https://bitcoinfees.21.co and use a fee that will allow your transaction to be confirmed as soon as possible.

  • leftover (str) – The destination that will receive any change from the transaction. By default Bit will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bit should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bit will consolidate UTXOs. Note: When setting :param absolute_fee: this is ignored.

  • message (str) – A message to include in the transaction. This will be stored in the blockchain forever. Due to size limits, each message will be stored in chunks of 40 bytes.

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

  • replace_by_fee (bool) – Whether to opt-in for replace-by-fee (BIP 125).

Returns

JSON storing data required to create an offline transaction.

Return type

str

property scriptcode
property segwit_address

The public segwit nested in P2SH address you share with others to receive funds.

property segwit_scriptcode
sign(data)

Signs some data which can be verified later by others using the public key.

Parameters

data (bytes) – The message to sign.

Returns

A signature compliant with BIP-62.

Return type

bytes

sign_transaction(tx_data, unspents=None)

Creates a signed P2SH transaction using previously prepared transaction data.

Parameters
  • tx_data (str) – Hex-encoded transaction or output of prepare_transaction().

  • unspents (list of Unspent) – The UTXOs to use as the inputs. By default Bit will communicate with the blockchain itself.

Returns

The signed transaction as hex.

Return type

str

class bit.wallet.BaseKey(wif=None)

This class represents a point on the elliptic curve secp256k1 and provides all necessary cryptographic functionality. You shouldn’t use this class directly.

Parameters

wif (str) – A private key serialized to the Wallet Import Format. If the argument is not supplied, a new private key will be created. The WIF compression flag will be adhered to, but the version byte is disregarded. Compression will be used by all new keys.

Raises

TypeError – If wif is not a str.

is_compressed()

Returns whether or not this private key corresponds to a compressed public key.

Return type

bool

pub_to_hex()
Return type

str

property public_key

The public point serialized to bytes.

property public_point

The public point (x, y).

sign(data)

Signs some data which can be verified later by others using the public key.

Parameters

data (bytes) – The message to sign.

Returns

A signature compliant with BIP-62.

Return type

bytes

to_bytes()
Return type

bytes

to_der()
Return type

bytes

to_hex()
Return type

str

to_int()
Return type

int

to_pem()
Return type

bytes

verify(signature, data)

Verifies some data was signed by this private key.

Parameters
  • signature (bytes) – The signature to verify.

  • data (bytes) – The data that was supposedly signed.

Return type

bool

Network

class bit.network.NetworkAPI
BROADCAST_TX_MAIN = [<bound method BlockchairAPI.broadcast_tx of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.broadcast_tx of <class 'bit.network.services.BlockstreamAPI'>>, <bound method InsightAPI.broadcast_tx of <class 'bit.network.services.BitcoreAPI'>>, <bound method SmartbitAPI.broadcast_tx of <class 'bit.network.services.SmartbitAPI'>>, <bound method BlockchainAPI.broadcast_tx of <class 'bit.network.services.BlockchainAPI'>>]
BROADCAST_TX_TEST = [<bound method BlockchairAPI.broadcast_tx_testnet of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.broadcast_tx_testnet of <class 'bit.network.services.BlockstreamAPI'>>, <bound method BitcoreAPI.broadcast_tx_testnet of <class 'bit.network.services.BitcoreAPI'>>, <bound method SmartbitAPI.broadcast_tx_testnet of <class 'bit.network.services.SmartbitAPI'>>]
GET_BALANCE_MAIN = [<bound method BlockchairAPI.get_balance of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.get_balance of <class 'bit.network.services.BlockstreamAPI'>>, <bound method BitcoreAPI.get_balance of <class 'bit.network.services.BitcoreAPI'>>, <bound method SmartbitAPI.get_balance of <class 'bit.network.services.SmartbitAPI'>>, <bound method BlockchainAPI.get_balance of <class 'bit.network.services.BlockchainAPI'>>]
GET_BALANCE_TEST = [<bound method BlockchairAPI.get_balance_testnet of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.get_balance_testnet of <class 'bit.network.services.BlockstreamAPI'>>, <bound method BitcoreAPI.get_balance_testnet of <class 'bit.network.services.BitcoreAPI'>>, <bound method SmartbitAPI.get_balance_testnet of <class 'bit.network.services.SmartbitAPI'>>]
GET_TRANSACTIONS_MAIN = [<bound method BlockchairAPI.get_transactions of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.get_transactions of <class 'bit.network.services.BlockstreamAPI'>>, <bound method SmartbitAPI.get_transactions of <class 'bit.network.services.SmartbitAPI'>>, <bound method BlockchainAPI.get_transactions of <class 'bit.network.services.BlockchainAPI'>>]
GET_TRANSACTIONS_TEST = [<bound method BlockchairAPI.get_transactions_testnet of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.get_transactions_testnet of <class 'bit.network.services.BlockstreamAPI'>>, <bound method SmartbitAPI.get_transactions_testnet of <class 'bit.network.services.SmartbitAPI'>>]
GET_TRANSACTION_BY_ID_MAIN = [<bound method BlockchairAPI.get_transaction_by_id of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.get_transaction_by_id of <class 'bit.network.services.BlockstreamAPI'>>, <bound method SmartbitAPI.get_transaction_by_id of <class 'bit.network.services.SmartbitAPI'>>, <bound method BlockchainAPI.get_transaction_by_id of <class 'bit.network.services.BlockchainAPI'>>]
GET_TRANSACTION_BY_ID_TEST = [<bound method BlockchairAPI.get_transaction_by_id_testnet of <class 'bit.network.services.BlockchairAPI'>>, <bound method BlockstreamAPI.get_transaction_by_id_testnet of <class 'bit.network.services.BlockstreamAPI'>>, <bound method SmartbitAPI.get_transaction_by_id_testnet of <class 'bit.network.services.SmartbitAPI'>>]
GET_UNSPENT_MAIN = [<bound method BlockstreamAPI.get_unspent of <class 'bit.network.services.BlockstreamAPI'>>, <bound method BlockchairAPI.get_unspent of <class 'bit.network.services.BlockchairAPI'>>, <bound method SmartbitAPI.get_unspent of <class 'bit.network.services.SmartbitAPI'>>, <bound method BlockchainAPI.get_unspent of <class 'bit.network.services.BlockchainAPI'>>, <bound method BitcoreAPI.get_unspent of <class 'bit.network.services.BitcoreAPI'>>]
GET_UNSPENT_TEST = [<bound method BlockstreamAPI.get_unspent_testnet of <class 'bit.network.services.BlockstreamAPI'>>, <bound method BlockchairAPI.get_unspent_testnet of <class 'bit.network.services.BlockchairAPI'>>, <bound method SmartbitAPI.get_unspent_testnet of <class 'bit.network.services.SmartbitAPI'>>, <bound method BitcoreAPI.get_unspent_testnet of <class 'bit.network.services.BitcoreAPI'>>]
IGNORED_ERRORS = (<class 'ConnectionError'>, <class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.Timeout'>, <class 'requests.exceptions.ReadTimeout'>, <class 'bit.exceptions.ExcessiveAddress'>)
classmethod broadcast_tx(tx_hex)

Broadcasts a transaction to the blockchain.

Parameters

tx_hex (str) – A signed transaction in hex form.

Raises

ConnectionError – If all API services fail.

classmethod broadcast_tx_testnet(tx_hex)

Broadcasts a transaction to the test network’s blockchain.

Parameters

tx_hex (str) – A signed transaction in hex form.

Raises

ConnectionError – If all API services fail.

classmethod connect_to_node(user, password, host='localhost', port=8332, use_https=False, testnet=False)

Connect to a remote Bitcoin node instead of using web APIs. Allows to connect to a testnet and mainnet Bitcoin node simultaneously.

Parameters
  • user (str) – The RPC user to a Bitcoin node

  • password (str) – The RPC password to a Bitcoin node

  • host (str) – The host to a Bitcoin node

  • port (int) – The port to a Bitcoin node

  • use_https (bool or string) – Connect to the Bitcoin node via HTTPS. Either a boolean, in which case it controls whether we connect to the node via HTTP or HTTPS, or a string, in which case we connect via HTTPS and it must be a path to the CA bundle to use. Defaults to False.

  • testnet (bool) – Defines if the node should be used for testnet

Returns

The node exposing its RPCs for direct interaction.

Return type

RPCHost

classmethod get_balance(address)

Gets the balance of an address in satoshi.

Parameters

address (str) – The address in question.

Raises

ConnectionError – If all API services fail.

Return type

int

classmethod get_balance_testnet(address)

Gets the balance of an address on the test network in satoshi.

Parameters

address (str) – The address in question.

Raises

ConnectionError – If all API services fail.

Return type

int

classmethod get_transaction_by_id(txid)

Gets a raw transaction hex by its transaction id (txid).

Parameters

txid (str) – The id of the transaction

Raises

ConnectionError – If all API services fail.

Return type

string

classmethod get_transaction_by_id_testnet(txid)

Gets a raw transaction hex by its transaction id (txid) on the test.

Parameters

txid (str) – The id of the transaction

Raises

ConnectionError – If all API services fail.

Return type

string

classmethod get_transactions(address)

Gets the ID of all transactions related to an address.

Parameters

address (str) – The address in question.

Raises

ConnectionError – If all API services fail.

Return type

list of str

classmethod get_transactions_testnet(address)

Gets the ID of all transactions related to an address on the test network.

Parameters

address (str) – The address in question.

Raises

ConnectionError – If all API services fail.

Return type

list of str

classmethod get_unspent(address)

Gets all unspent transaction outputs belonging to an address.

Parameters

address (str) – The address in question.

Raises

ConnectionError – If all API services fail.

Return type

list of Unspent

classmethod get_unspent_testnet(address)

Gets all unspent transaction outputs belonging to an address on the test network.

Parameters

address (str) – The address in question.

Raises

ConnectionError – If all API services fail.

Return type

list of Unspent

class bit.network.services.BitcoreAPI

Insight API v8

MAIN_ADDRESS_API = 'https://api.bitcore.io/api/BTC/mainnet/address/{}'
MAIN_BALANCE_API = 'https://api.bitcore.io/api/BTC/mainnet/address/{}/balance'
MAIN_ENDPOINT = 'https://api.bitcore.io/api/BTC/mainnet/'
MAIN_TX_AMOUNT_API = 'https://api.bitcore.io/api/BTC/mainnet/tx/{}'
MAIN_TX_API = 'https://api.bitcore.io/api/BTC/mainnet/tx/{}'
MAIN_TX_PUSH_API = 'https://api.bitcore.io/api/BTC/mainnet/tx/send'
MAIN_UNSPENT_API = 'https://api.bitcore.io/api/BTC/mainnet/address/{}/?unspent=true'
TEST_ADDRESS_API = 'https://api.bitcore.io/api/BTC/testnet/address/{}'
TEST_BALANCE_API = 'https://api.bitcore.io/api/BTC/testnet/address/{}/balance'
TEST_ENDPOINT = 'https://api.bitcore.io/api/BTC/testnet/'
TEST_TX_AMOUNT_API = 'https://api.bitcore.io/api/BTC/testnet/tx/{}'
TEST_TX_API = 'https://api.bitcore.io/api/BTC/testnet/tx/{}'
TEST_TX_PUSH_API = 'https://api.bitcore.io/api/BTC/testnet/tx/send'
TEST_UNSPENT_API = 'https://api.bitcore.io/api/BTC/testnet/address/{}/?unspent=true'
TX_PUSH_PARAM = 'rawTx'
classmethod broadcast_tx(tx_hex)
classmethod broadcast_tx_testnet(tx_hex)
classmethod get_balance(address)
classmethod get_balance_testnet(address)
classmethod get_transaction_by_id(txid)
classmethod get_transactions(address)
classmethod get_unspent(address)
classmethod get_unspent_testnet(address)
class bit.network.services.BlockchairAPI
MAIN_ADDRESS_API = 'https://api.blockchair.com/bitcoin/dashboards/address/{}'
MAIN_ENDPOINT = 'https://api.blockchair.com/bitcoin/'
MAIN_TX_API = 'https://api.blockchair.com/bitcoin/raw/transaction/{}'
MAIN_TX_PUSH_API = 'https://api.blockchair.com/bitcoin/push/transaction'
TEST_ADDRESS_API = 'https://api.blockchair.com/bitcoin/testnet/dashboards/address/{}'
TEST_ENDPOINT = 'https://api.blockchair.com/bitcoin/testnet/'
TEST_TX_API = 'https://api.blockchair.com/bitcoin/testnet/raw/transaction/{}'
TEST_TX_PUSH_API = 'https://api.blockchair.com/bitcoin/testnet/push/transaction'
TX_PUSH_PARAM = 'data'
classmethod broadcast_tx(tx_hex)
classmethod broadcast_tx_testnet(tx_hex)
classmethod get_balance(address)
classmethod get_balance_testnet(address)
classmethod get_transaction_by_id(txid)
classmethod get_transaction_by_id_testnet(txid)
classmethod get_transactions(address)
classmethod get_transactions_testnet(address)
classmethod get_unspent(address)
classmethod get_unspent_testnet(address)
class bit.network.services.BlockstreamAPI
MAIN_ADDRESS_API = 'https://blockstream.info/api/address/{}'
MAIN_ENDPOINT = 'https://blockstream.info/api/'
MAIN_TX_API = 'https://blockstream.info/api/tx/{}/hex'
MAIN_TX_PUSH_API = 'https://blockstream.info/api/tx'
MAIN_UNSPENT_API = 'https://blockstream.info/api/address/{}/utxo'
TEST_ADDRESS_API = 'https://blockstream.info/testnet/api/address/{}'
TEST_ENDPOINT = 'https://blockstream.info/testnet/api/'
TEST_TX_API = 'https://blockstream.info/testnet/api/tx/{}/hex'
TEST_TX_PUSH_API = 'https://blockstream.info/testnet/api/tx'
TEST_UNSPENT_API = 'https://blockstream.info/testnet/api/address/{}/utxo'
TX_PUSH_PARAM = 'data'
classmethod broadcast_tx(tx_hex)
classmethod broadcast_tx_testnet(tx_hex)
classmethod get_balance(address)
classmethod get_balance_testnet(address)
classmethod get_transaction_by_id(txid)
classmethod get_transaction_by_id_testnet(txid)
classmethod get_transactions(address)
classmethod get_transactions_testnet(address)
classmethod get_unspent(address)
classmethod get_unspent_testnet(address)
class bit.network.services.BlockchainAPI
ADDRESS_API = 'https://blockchain.info/address/{}?format=json'
ENDPOINT = 'https://blockchain.info/'
TX_API = 'https://blockchain.info/rawtx/'
TX_PUSH_API = 'https://blockchain.info/pushtx'
TX_PUSH_PARAM = 'tx'
UNSPENT_API = 'https://blockchain.info/unspent'
classmethod broadcast_tx(tx_hex)
classmethod get_balance(address)
classmethod get_transaction_by_id(txid)
classmethod get_transactions(address)
classmethod get_unspent(address)
class bit.network.services.SmartbitAPI
MAIN_ADDRESS_API = 'https://api.smartbit.com.au/v1/blockchain/address/{}'
MAIN_ENDPOINT = 'https://api.smartbit.com.au/v1/blockchain/'
MAIN_TX_API = 'https://api.smartbit.com.au/v1/blockchain/tx/{}/hex'
MAIN_TX_PUSH_API = 'https://api.smartbit.com.au/v1/blockchain/pushtx'
MAIN_UNSPENT_API = 'https://api.smartbit.com.au/v1/blockchain/address/{}/unspent'
TEST_ADDRESS_API = 'https://testnet-api.smartbit.com.au/v1/blockchain/address/{}'
TEST_ENDPOINT = 'https://testnet-api.smartbit.com.au/v1/blockchain/'
TEST_TX_API = 'https://testnet-api.smartbit.com.au/v1/blockchain/tx/{}/hex'
TEST_TX_PUSH_API = 'https://testnet-api.smartbit.com.au/v1/blockchain/pushtx'
TEST_UNSPENT_API = 'https://testnet-api.smartbit.com.au/v1/blockchain/address/{}/unspent'
TX_PUSH_PARAM = 'hex'
classmethod broadcast_tx(tx_hex)
classmethod broadcast_tx_testnet(tx_hex)
classmethod get_balance(address)
classmethod get_balance_testnet(address)
classmethod get_transaction_by_id(txid)
classmethod get_transaction_by_id_testnet(txid)
classmethod get_transactions(address)
classmethod get_transactions_testnet(address)
classmethod get_unspent(address)
classmethod get_unspent_testnet(address)
class bit.network.meta.Unspent(amount, confirmations, script, txid, txindex, type='p2pkh', vsize=None, segwit=None, sequence=4294967295)

Represents an unspent transaction output (UTXO).

amount
confirmations
classmethod from_dict(d)
opt_in_for_RBF()
script
segwit
sequence
set_type(type, vsize=0)
to_dict()
txid
txindex
type
vsize

Exchange Rates

bit.network.currency_to_satoshi(amount, currency)

Converts a given amount of currency to the equivalent number of satoshi. The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal.

Parameters
Return type

int

bit.network.currency_to_satoshi_cached(amount, currency)

Converts a given amount of currency to the equivalent number of satoshi. The amount can be either an int, float, or string as long as it is a valid input to decimal.Decimal. Results are cached using a decorator for 60 seconds by default. See Cache Times.

Parameters
Return type

int

bit.network.satoshi_to_currency(num, currency)

Converts a given number of satoshi to another currency as a formatted string rounded down to the proper number of decimal places.

Parameters
Return type

str

bit.network.satoshi_to_currency_cached(num, currency)

Converts a given number of satoshi to another currency as a formatted string rounded down to the proper number of decimal places. Results are cached using a decorator for 60 seconds by default. See Cache Times.

Parameters
Return type

str

class bit.network.rates.RatesAPI

Each method converts exactly 1 unit of the currency to the equivalent number of satoshi.

AUD_RATES = [<bound method BitpayRates.aud_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.aud_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
BRL_RATES = [<bound method BitpayRates.brl_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.brl_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
CAD_RATES = [<bound method BitpayRates.cad_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.cad_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
CHF_RATES = [<bound method BitpayRates.chf_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.chf_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
CLP_RATES = [<bound method BitpayRates.clp_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.clp_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
CNY_RATES = [<bound method BitpayRates.cny_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.cny_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
DKK_RATES = [<bound method BitpayRates.dkk_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.dkk_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
EUR_RATES = [<bound method BitpayRates.eur_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.eur_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
GBP_RATES = [<bound method BitpayRates.gbp_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.gbp_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
HKD_RATES = [<bound method BitpayRates.hkd_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.hkd_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
IGNORED_ERRORS = (<class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.HTTPError'>, <class 'requests.exceptions.Timeout'>)
ISK_RATES = [<bound method BitpayRates.isk_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.isk_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
JPY_RATES = [<bound method BitpayRates.jpy_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.jpy_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
KRW_RATES = [<bound method BitpayRates.krw_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.krw_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
NZD_RATES = [<bound method BitpayRates.nzd_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.nzd_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
PLN_RATES = [<bound method BitpayRates.pln_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.pln_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
RUB_RATES = [<bound method BitpayRates.rub_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.rub_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
SEK_RATES = [<bound method BitpayRates.sek_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.sek_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
SGD_RATES = [<bound method BitpayRates.sgd_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.sgd_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
THB_RATES = [<bound method BitpayRates.thb_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.thb_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
TWD_RATES = [<bound method BitpayRates.twd_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.twd_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
USD_RATES = [<bound method BitpayRates.usd_to_satoshi of <class 'bit.network.rates.BitpayRates'>>, <bound method BlockchainRates.usd_to_satoshi of <class 'bit.network.rates.BlockchainRates'>>]
classmethod aud_to_satoshi()
classmethod brl_to_satoshi()
classmethod cad_to_satoshi()
classmethod chf_to_satoshi()
classmethod clp_to_satoshi()
classmethod cny_to_satoshi()
classmethod dkk_to_satoshi()
classmethod eur_to_satoshi()
classmethod gbp_to_satoshi()
classmethod hkd_to_satoshi()
classmethod isk_to_satoshi()
classmethod jpy_to_satoshi()
classmethod krw_to_satoshi()
classmethod nzd_to_satoshi()
classmethod pln_to_satoshi()
classmethod rub_to_satoshi()
classmethod sek_to_satoshi()
classmethod sgd_to_satoshi()
classmethod thb_to_satoshi()
classmethod twd_to_satoshi()
classmethod usd_to_satoshi()
class bit.network.rates.BitpayRates

API Documentation: https://bitpay.com/api/rates#rest-api-resources-rates

SINGLE_RATE = 'https://bitpay.com/rates/BTC/'
classmethod aud_to_satoshi()
classmethod brl_to_satoshi()
classmethod cad_to_satoshi()
classmethod chf_to_satoshi()
classmethod clp_to_satoshi()
classmethod cny_to_satoshi()
classmethod currency_to_satoshi(currency)
classmethod dkk_to_satoshi()
classmethod eur_to_satoshi()
classmethod gbp_to_satoshi()
classmethod hkd_to_satoshi()
classmethod isk_to_satoshi()
classmethod jpy_to_satoshi()
classmethod krw_to_satoshi()
classmethod nzd_to_satoshi()
classmethod pln_to_satoshi()
classmethod rub_to_satoshi()
classmethod sek_to_satoshi()
classmethod sgd_to_satoshi()
classmethod thb_to_satoshi()
classmethod twd_to_satoshi()
classmethod usd_to_satoshi()
class bit.network.rates.BlockchainRates
SINGLE_RATE = 'https://blockchain.info/tobtc?currency={}&value=1'
classmethod aud_to_satoshi()
classmethod brl_to_satoshi()
classmethod cad_to_satoshi()
classmethod chf_to_satoshi()
classmethod clp_to_satoshi()
classmethod cny_to_satoshi()
classmethod currency_to_satoshi(currency)
classmethod dkk_to_satoshi()
classmethod eur_to_satoshi()
classmethod gbp_to_satoshi()
classmethod hkd_to_satoshi()
classmethod isk_to_satoshi()
classmethod jpy_to_satoshi()
classmethod krw_to_satoshi()
classmethod nzd_to_satoshi()
classmethod pln_to_satoshi()
classmethod rub_to_satoshi()
classmethod sek_to_satoshi()
classmethod sgd_to_satoshi()
classmethod thb_to_satoshi()
classmethod twd_to_satoshi()
classmethod usd_to_satoshi()

Fees

bit.network.get_fee(fast=True)

Gets the recommended satoshi per byte fee.

Parameters

fast (bool) – If True, the fee returned will be “The lowest fee (in satoshis per byte) that will currently result in the fastest transaction confirmations (usually 0 to 1 block delay)”. Otherwise, the number returned will be “The lowest fee (in satoshis per byte) that will confirm transactions within an hour (with 90% probability)”.

Return type

int

bit.network.get_fee_cached(fast=True)

Gets the recommended satoshi per byte fee. Results are cached using a decorator for 10 minutes by default. See Cache Times.

Parameters

fast (bool) – If True, the fee returned will be “The lowest fee (in satoshis per byte) that will currently result in the fastest transaction confirmations (usually 0 to 1 block delay)”. Otherwise, the number returned will be “The lowest fee (in satoshis per byte) that will confirm transactions within an hour (with 90% probability)”.

Return type

int

Utilities

bit.verify_sig(signature, data, public_key)

Verifies some data was signed by the owner of a public key.

Parameters
  • signature (bytes) – The signature to verify.

  • data (bytes) – The data that was supposedly signed.

  • public_key (bytes) – The public key.

Returns

True if all checks pass, False otherwise.

Exceptions

exception bit.exceptions.InsufficientFunds
exception bit.exceptions.BitcoinNodeException
exception bit.exceptions.ExcessiveAddress