Developer Interface

Keys

bitcash.Key

alias of PrivateKey

class bitcash.PrivateKey(wif: str | PrivateKey | None = None, network: Literal['main'] | Literal['test'] | Literal['regtest'] = 'main')

This class represents a BitcoinCash 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: str

The public address you share with others to receive funds.

balance_as(currency: str) str

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

Parameters:

currency (str) – One of the Supported Currencies.

Return type:

str

property cashtoken_address: str

The public address you share with others to receive cashtokens.

create_transaction(outputs: Sequence[tuple[str, int, str] | tuple[str, int, str, str | None, str | None, bytes | None, int | None]], fee: int | None = None, leftover: str | None = None, combine: bool = True, message: bytes | str | None = None, unspents: list[Unspent] | None = None, custom_pushdata: bool = False) str

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. To send CashToken, the list of output is made in the form (destination, amount, currency, category_id, nft_capability, nft_commitment, token_amount). The category_id is hex of tx-id as str. The nft_capability is the capability of non-fungible token in (“none”, “mutable”, “minting”). The nft_commitment is the commitment of the non-fungible token in bytes. The CashToken property nft_capability, nft_commitment, or the token_amount can be None if not to be sent. If category_id is tx-id of unspent with tx-index 0, then tx is treated as a genesis tx.

  • fee (int) – The number of satoshi per byte to pay to miners. By default Bitcash will poll https://bitcoincashfees.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 Bitcash will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bitcash should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bitcash will consolidate UTXOs.

  • 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 220 bytes.

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

Returns:

The signed transaction as hex.

Return type:

str

classmethod from_bytes(bytestr: bytes) PrivateKey
Parameters:

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

Return type:

PrivateKey

classmethod from_der(der: bytes) PrivateKey
Parameters:

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

Return type:

PrivateKey

classmethod from_hex(hexed: str) PrivateKey
Parameters:

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

Return type:

PrivateKey

classmethod from_int(num: int) PrivateKey
Parameters:

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

Return type:

PrivateKey

classmethod from_pem(pem: bytes) PrivateKey
Parameters:

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

Return type:

PrivateKey

get_balance(currency: str = 'satoshi') str

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

Parameters:

currency (str) – One of the Supported Currencies.

Return type:

str

get_cashtokenbalance() dict[str, TokenData]

Fetches the current cashtoken balance by calling get_balance() and returns it as a token dictionary.

Return type:

dict

get_transactions() list[str]

Fetches transaction history.

Return type:

list of str transaction IDs

get_unspents() list[Unspent]

Fetches all available unspent transaction outputs.

Return type:

list of Unspent

is_compressed() bool

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

Return type:

bool

classmethod prepare_transaction(address: str, outputs: Sequence[tuple[str, int, str] | tuple[str, int, str, str | None, str | None, bytes | None, int | None]], compressed: bool = True, fee: int | None = None, leftover: str | None = None, combine: bool = True, message: bytes | str | None = None, unspents: list[Unspent] | None = None)

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. To send CashToken, the list of output is made in the form (destination, amount, currency, category_id, nft_capability, nft_commitment, token_amount). The category_id is hex of tx-id as str. The nft_capability is the capability of non-fungible token in (“none”, “mutable”, “minting”). The nft_commitment is the commitment of the non-fungible token in bytes. The CashToken property nft_capability, nft_commitment, or the token_amount can be None if not to be sent. If category_id is tx-id of unspent with tx-index 0, then tx is treated as a genesis tx.

  • 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 Bitcash will poll https://bitcoincashfees.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 Bitcash will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bitcash should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bitcash will consolidate UTXOs.

  • 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 220 bytes.

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

Returns:

JSON storing data required to create an offline transaction.

Return type:

str

property public_key: bytes

The public point serialized to bytes.

property public_point: Point

The public point (x, y).

property scriptcode: bytes
send(outputs: Sequence[tuple[str, int, str] | tuple[str, int, str, str | None, str | None, bytes | None, int | None]], fee: int | None = None, leftover: str | None = None, combine: bool = True, message: bytes | str | None = None, unspents: list[Unspent] | None = None)

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. To send CashToken, the list of output is made in the form (destination, amount, currency, category_id, nft_capability, nft_commitment, token_amount). The category_id is hex of tx-id as str. The nft_capability is the capability of non-fungible token in (“none”, “mutable”, “minting”). The nft_commitment is the commitment of the non-fungible token in bytes. The CashToken property nft_capability, nft_commitment, or the token_amount can be None if not to be sent. If category_id is tx-id of unspent with tx-index 0, then tx is treated as a genesis tx.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bitcash will poll https://bitcoincashfees.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 Bitcash will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bitcash should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bitcash will consolidate UTXOs.

  • 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 220 bytes.

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

Returns:

The transaction ID.

Return type:

str

sign(data: bytes) bytes

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: str) str

Creates a signed P2PKH transaction using previously prepared transaction data.

Parameters:

tx_data (str) – Output of prepare_transaction().

Returns:

The signed transaction as hex.

Return type:

str

to_bytes() bytes
Return type:

bytes

to_der() bytes
Return type:

bytes

to_hex() str
Return type:

str

to_int() int
Return type:

int

to_pem() bytes
Return type:

bytes

to_wif() str
verify(signature: bytes, data: bytes) bool

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 bitcash.PrivateKeyTestnet(wif: str | PrivateKey | None = None, network: Literal['main'] | Literal['test'] | Literal['regtest'] = 'test')

This class represents a testnet BitcoinCash 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: str

The public address you share with others to receive funds.

balance_as(currency: str) str

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

Parameters:

currency (str) – One of the Supported Currencies.

Return type:

str

property cashtoken_address: str

The public address you share with others to receive cashtokens.

create_transaction(outputs: Sequence[tuple[str, int, str] | tuple[str, int, str, str | None, str | None, bytes | None, int | None]], fee: int | None = None, leftover: str | None = None, combine: bool = True, message: bytes | str | None = None, unspents: list[Unspent] | None = None, custom_pushdata: bool = False) str

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. To send CashToken, the list of output is made in the form (destination, amount, currency, category_id, nft_capability, nft_commitment, token_amount). The category_id is hex of tx-id as str. The nft_capability is the capability of non-fungible token in (“none”, “mutable”, “minting”). The nft_commitment is the commitment of the non-fungible token in bytes. The CashToken property nft_capability, nft_commitment, or the token_amount can be None if not to be sent. If category_id is tx-id of unspent with tx-index 0, then tx is treated as a genesis tx.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bitcash will poll https://bitcoincashfees.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 Bitcash will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bitcash should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bitcash will consolidate UTXOs.

  • 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 220 bytes.

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

Returns:

The signed transaction as hex.

Return type:

str

classmethod from_bytes(bytestr: bytes) PrivateKeyTestnet
Parameters:

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

Return type:

PrivateKeyTestnet

classmethod from_der(der: bytes) PrivateKeyTestnet
Parameters:

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

Return type:

PrivateKeyTestnet

classmethod from_hex(hexed: str) PrivateKeyTestnet
Parameters:

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

Return type:

PrivateKeyTestnet

classmethod from_int(num: int) PrivateKeyTestnet
Parameters:

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

Return type:

PrivateKeyTestnet

classmethod from_pem(pem: bytes) PrivateKeyTestnet
Parameters:

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

Return type:

PrivateKeyTestnet

get_balance(currency: str = 'satoshi') str

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

Parameters:

currency (str) – One of the Supported Currencies.

Return type:

str

get_cashtokenbalance() dict[str, TokenData]

Fetches the current cashtoken balance by calling get_balance() and returns it as a token dictionary.

Return type:

dict

get_transactions() list[str]

Fetches transaction history.

Return type:

list of str transaction IDs

get_unspents() list[Unspent]

Fetches all available unspent transaction outputs.

Return type:

list of Unspent

is_compressed() bool

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

Return type:

bool

classmethod prepare_transaction(address: str, outputs: Sequence[tuple[str, int, str] | tuple[str, int, str, str | None, str | None, bytes | None, int | None]], compressed: bool = True, fee: int | None = None, leftover: str | None = None, combine: bool = True, message: bytes | str | None = None, unspents: list[Unspent] | None = None)

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. To send CashToken, the list of output is made in the form (destination, amount, currency, category_id, nft_capability, nft_commitment, token_amount). The category_id is hex of tx-id as str. The nft_capability is the capability of non-fungible token in (“none”, “mutable”, “minting”). The nft_commitment is the commitment of the non-fungible token in bytes. The CashToken property nft_capability, nft_commitment, or the token_amount can be None if not to be sent. If category_id is tx-id of unspent with tx-index 0, then tx is treated as a genesis tx.

  • 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 Bitcash will poll https://bitcoincashfees.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 Bitcash will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bitcash should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bitcash will consolidate UTXOs.

  • 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 220 bytes.

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

Returns:

JSON storing data required to create an offline transaction.

Return type:

str

property public_key: bytes

The public point serialized to bytes.

property public_point: Point

The public point (x, y).

property scriptcode: bytes
send(outputs: Sequence[tuple[str, int, str] | tuple[str, int, str, str | None, str | None, bytes | None, int | None]], fee: int | None = None, leftover: str | None = None, combine: bool = True, message: bytes | str | None = None, unspents: list[Unspent] | None = None)

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. To send CashToken, the list of output is made in the form (destination, amount, currency, category_id, nft_capability, nft_commitment, token_amount). The category_id is hex of tx-id as str. The nft_capability is the capability of non-fungible token in (“none”, “mutable”, “minting”). The nft_commitment is the commitment of the non-fungible token in bytes. The CashToken property nft_capability, nft_commitment, or the token_amount can be None if not to be sent. If category_id is tx-id of unspent with tx-index 0, then tx is treated as a genesis tx.

  • fee (int) –

    The number of satoshi per byte to pay to miners. By default Bitcash will poll https://bitcoincashfees.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 Bitcash will send any change to the same address you sent from.

  • combine (bool) – Whether or not Bitcash should use all available UTXOs to make future transactions smaller and therefore reduce fees. By default Bitcash will consolidate UTXOs.

  • 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 220 bytes.

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

Returns:

The transaction ID.

Return type:

str

sign(data: bytes) bytes

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: str) str

Creates a signed P2PKH transaction using previously prepared transaction data.

Parameters:

tx_data (str) – Output of prepare_transaction().

Returns:

The signed transaction as hex.

Return type:

str

to_bytes() bytes
Return type:

bytes

to_der() bytes
Return type:

bytes

to_hex() str
Return type:

str

to_int() int
Return type:

int

to_pem() bytes
Return type:

bytes

to_wif() str
verify(signature: bytes, data: bytes) bool

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 bitcash.wallet.BaseKey(wif: str | PrivateKey | None = None, regtest: bool = False)

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() bool

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

Return type:

bool

property public_key: bytes

The public point serialized to bytes.

property public_point: Point

The public point (x, y).

sign(data: bytes) bytes

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() bytes
Return type:

bytes

to_der() bytes
Return type:

bytes

to_hex() str
Return type:

str

to_int() int
Return type:

int

to_pem() bytes
Return type:

bytes

verify(signature: bytes, data: bytes) bool

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

CashAddress

class bitcash.cashaddress.Address(version: str, payload: list[int])

Class to handle CashAddr.

Parameters:
  • version – Version of CashAddr

  • payload – Payload of CashAddr as int list of the bytearray

cash_address() str

Generate CashAddr of the Address

classmethod from_script(scriptcode: bytes) Address

Generate Address from a locking script

Parameters:

scriptcode – The locking script

Returns:

Instance of :class:~bitcash.cashaddress.Address

classmethod from_string(address: str) Address

Generate Address from a cashadress string

Parameters:

scriptcode – The cashaddress string

Returns:

Instance of :class:~bitcash.cashaddress.Address

property scriptcode: bytes

Generate the locking script of the Address

bitcash.cashaddress.generate_cashaddress(address: str, params: dict[str, Any] | None = None) str

Generates cashaddress uri from address and params

Parameters:
  • address – cashaddress

  • params – dictionary of parameters to be attached

Returns:

cashaddress uri

>>> generate_cashaddress(
        "bitcoincash:qzfyvx77v2pmgc0vulwlfkl3uzjgh5gnmqk5hhyaa6",
        {
            "amount": 0.1,
        }
)
"bitcoincash:qzfyvx77v2pmgc0vulwlfkl3uzjgh5gnmqk5hhyaa6?amount=0.1"
>>> generate_cashaddress(
        "bitcoincash:",
        {"message": "Satoshi Nakamoto"}
)
"bitcoincash:?message=Satoshi%20Nakamoto"
bitcash.cashaddress.parse_cashaddress(data: str) tuple[Address | None, dict[str, Any]]

Parse CashAddress address URI, with params attached

Parameters:

data – Cashaddress uri to be parsed

Returns:

cashaddress address, and parameters

>>> parse_cashaddress(
        'bchtest:qzvsaasdvw6mt9j2rs3gyps673gj86flev3z0s40ln?'
        'amount=0.1337&label=Satoshi-Nakamoto&message=Donation%20xyz'
    )
(<bitcash.cashaddress.Address>,
 {'amount': '0.1337',
  'label': 'Satoshi-Nakamoto',
  'message': 'Donation xyz'
 }
)
>>> parse_cashaddress(
        'bchtest:?label=Satoshi-Nakamoto&message=Donation%20xyz'
    )
(None,
 {'label': 'Satoshi-Nakamoto',
  'message': 'Donation xyz'
 }
)

CashTokens

bitcash.cashtoken.parse_cashtoken_prefix(script: bytes) CashTokens

Parses cashtoken prefix

Parameters:

script – Token prefix with OP_TOKENPREFIX

Returns:

:class:~bitcash.types.CashTokens

bitcash.cashtoken.generate_cashtoken_prefix(cashtoken: CashTokens) bytes

Generates cashtoken prefix from cashtoken data

Parameters:

cashtoken_output – Cashtoken output data

Returns:

Cahstoken prefix

bitcash.format.cashtokenaddress_to_address(address: str) str

Converts cashtoken signalling cashaddress to regular cashaddress

Parameters:

address – Cashtoken signalling cashaddress

Returns:

Cashaddress

Network

class bitcash.network.NetworkAPI
IGNORED_ERRORS = (<class 'requests.exceptions.RequestException'>, <class 'requests.exceptions.HTTPError'>, <class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.ProxyError'>, <class 'requests.exceptions.SSLError'>, <class 'requests.exceptions.Timeout'>, <class 'requests.exceptions.ConnectTimeout'>, <class 'requests.exceptions.ReadTimeout'>, <class 'requests.exceptions.TooManyRedirects'>, <class 'requests.exceptions.ChunkedEncodingError'>, <class 'requests.exceptions.ContentDecodingError'>, <class 'requests.exceptions.StreamConsumedError'>, <class 'ssl.SSLError'>, <class 'ssl.SSLZeroReturnError'>, <class 'ssl.SSLWantReadError'>, <class 'ssl.SSLWantWriteError'>, <class 'ssl.SSLSyscallError'>, <class 'ssl.SSLEOFError'>, <class 'OSError'>, <class 'TimeoutError'>, <class 'ConnectionResetError'>, <class 'ConnectionAbortedError'>, <class 'BrokenPipeError'>, <class 'OSError'>, <class 'TimeoutError'>)
classmethod broadcast_tx(tx_hex: str, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet')

Broadcasts a transaction to the blockchain.

Parameters:

tx_hex – A signed transaction in hex form.

Raises:
  • ConnectionError – If all API services fail.

  • RuntimeError – If the transaction broadcast fails.

classmethod get_balance(address: str, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet') int

Gets the balance of an address in satoshi.

Parameters:

address – The address in question.

Returns:

The balance in satoshi.

Raises:

ConnectionError – If all API services fail.

classmethod get_raw_transaction(txid: str, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet') dict[str, Any]

Gets the raw, unparsed transaction details.

Parameters:

txid – The transaction id in question.

Returns:

The raw transaction details.

Raises:

ConnectionError – If all API services fail.

classmethod get_transaction(txid: str, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet') Transaction

Gets the full transaction details.

Parameters:

txid – The transaction id in question.

Returns:

The transaction details.

Raises:

ConnectionError – If all API services fail.

classmethod get_transactions(address: str, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet') list[str]

Gets the ID of all transactions related to an address.

Parameters:

address – The address in question.

Returns:

A list of transaction ids.

Raises:

ConnectionError – If all API services fail.

classmethod get_tx_amount(txid: str, txindex: int, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet') int

Gets the amount of a given transaction output.

Parameters:
  • txid – The transaction id in question.

  • txindex – The transaction index in question.

Returns:

The amount in satoshi.

Raises:

ConnectionError – If all API services fail.

classmethod get_unspent(address: str, network: Literal['mainnet'] | Literal['testnet'] | Literal['regtest'] = 'mainnet') list[Unspent]

Gets all unspent transaction outputs belonging to an address.

Parameters:

address – The address in question.

Returns:

A list of unspent transaction outputs of Unspent.

Raises:

ConnectionError – If all API services fail.

class bitcash.network.meta.Unspent(amount: int, confirmations: int, script: str, txid: str, txindex: int, category_id: str | None = None, nft_capability: str | None = None, nft_commitment: bytes | None = None, token_amount: int | None = None)

Represents an unspent transaction output (UTXO) with CashToken

Parameters:
  • amount – Amount in satoshi

  • confirmations – Number of confirmations of the UTXO

  • script – locking bytecode hex of the UTXO, with no cashtoken prefix

  • txid – txid hex of the transaction of UTXO

  • txindex – transaction output index of UTXO

  • category_id – category_id of cashtoken attached to the UTXO

  • nft_capability – nft_capability of the cashtoken attached

  • nft_commitment – nft_commitment of the cashtoken attached

  • token_amount – fungible token amount of the cashtoken attached

amount
cashtoken
confirmations
classmethod from_dict(d: dict) Unspent
property has_amount: bool
property has_cashtoken: bool
property has_nft: bool
script
to_dict() dict
txid
txindex

Exchange Rates

bitcash.network.currency_to_satoshi(amount: int | float | str, currency: str) int

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:
bitcash.network.currency_to_satoshi_cached(amount: int, currency: str) int

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:
bitcash.network.satoshi_to_currency(num: int, currency: str) str

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

Parameters:
bitcash.network.satoshi_to_currency_cached(num: int, currency: str) str

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:
class bitcash.network.rates.RatesAPI

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

ARS_RATES = [<bound method BitpayRates.ars_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
AUD_RATES = [<bound method BitpayRates.aud_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
BOB_RATES = [<bound method BitpayRates.bob_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
BRL_RATES = [<bound method BitpayRates.brl_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
CAD_RATES = [<bound method BitpayRates.cad_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
CHF_RATES = [<bound method BitpayRates.chf_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
CLP_RATES = [<bound method BitpayRates.clp_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
CNY_RATES = [<bound method BitpayRates.cny_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
COP_RATES = [<bound method BitpayRates.cop_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
CUP_RATES = [<bound method BitpayRates.cup_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
DKK_RATES = [<bound method BitpayRates.dkk_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
DOP_RATES = [<bound method BitpayRates.dop_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
EUR_RATES = [<bound method BitpayRates.eur_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
GBP_RATES = [<bound method BitpayRates.gbp_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
HKD_RATES = [<bound method BitpayRates.hkd_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
IGNORED_ERRORS = (<class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.HTTPError'>, <class 'requests.exceptions.Timeout'>)
ISK_RATES = [<bound method BitpayRates.isk_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
JPY_RATES = [<bound method BitpayRates.jpy_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
KRW_RATES = [<bound method BitpayRates.krw_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
MXN_RATES = [<bound method BitpayRates.mxn_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
NZD_RATES = [<bound method BitpayRates.nzd_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
PEN_RATES = [<bound method BitpayRates.pen_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
PLN_RATES = [<bound method BitpayRates.pln_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
RUB_RATES = [<bound method BitpayRates.rub_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
SEK_RATES = [<bound method BitpayRates.sek_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
SGD_RATES = [<bound method BitpayRates.sgd_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
THB_RATES = [<bound method BitpayRates.thb_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
TWD_RATES = [<bound method BitpayRates.twd_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
USD_RATES = [<bound method BitpayRates.usd_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>, <bound method CoinbaseRates.usd_to_satoshi of <class 'bitcash.network.rates.CoinbaseRates'>>]
UYU_RATES = [<bound method BitpayRates.uyu_to_satoshi of <class 'bitcash.network.rates.BitpayRates'>>]
classmethod ars_to_satoshi()
classmethod aud_to_satoshi()
classmethod bob_to_satoshi()
classmethod brl_to_satoshi()
classmethod cad_to_satoshi()
classmethod chf_to_satoshi()
classmethod clp_to_satoshi()
classmethod cny_to_satoshi()
classmethod cop_to_satoshi()
classmethod cup_to_satoshi()
classmethod dkk_to_satoshi()
classmethod dop_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 mxn_to_satoshi()
classmethod nzd_to_satoshi()
classmethod pen_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()
classmethod uyu_to_satoshi()
class bitcash.network.rates.BitpayRates

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

SINGLE_RATE = 'https://bitpay.com/rates/BCH/'
classmethod ars_to_satoshi()
classmethod aud_to_satoshi()
classmethod bob_to_satoshi()
classmethod brl_to_satoshi()
classmethod cad_to_satoshi()
classmethod chf_to_satoshi()
classmethod clp_to_satoshi()
classmethod cny_to_satoshi()
classmethod cop_to_satoshi()
classmethod cup_to_satoshi()
classmethod currency_to_satoshi(currency: str) int
classmethod dkk_to_satoshi()
classmethod dop_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 mxn_to_satoshi()
classmethod nzd_to_satoshi()
classmethod pen_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() int
classmethod uyu_to_satoshi()

Utilities

bitcash.verify_sig(signature: bytes, data: bytes, public_key: bytes) bool

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

Parameters:
  • signature – The signature to verify.

  • data – The data that was supposedly signed.

  • public_key – The public key.

Returns:

True if all checks pass, False otherwise.

Exceptions

exception bitcash.exceptions.InsufficientFunds