Bitcoin Cash client

Bitcoin Cash client

class xchainpy2_bitcoincash.bch_client.BitcoinCashClient(network=NetworkType.MAINNET, phrase: str | None = None, private_key: str | bytes | callable | None = None, root_derivation_paths: Dict[NetworkType, str] | None = {NetworkType.MAINNET: "m/44'/145'/0'/0/", NetworkType.STAGENET: "m/44'/145'/0'/0/", NetworkType.TESTNET: "m/44'/1'/0'/0/"}, explorer_providers={NetworkType.MAINNET: ('https://blockchair.com/bch/', 'https://blockchair.com/bch/address/{address}', 'https://blockchair.com/bch/transaction/{tx_id}'), NetworkType.STAGENET: ('https://blockchair.com/bch/', 'https://blockchair.com/bch/address/{address}', 'https://blockchair.com/bch/transaction/{tx_id}'), NetworkType.TESTNET: ('https://blockchair.com/bch-testnet/', 'https://blockchair.com/bch-testnet/address/{address}', 'https://blockchair.com/bch-testnet/transaction/{tx_id}')}, wallet_index=0, provider_names=[], concurrency=5)

Bases: XChainClient

async broadcast_tx(tx_hex: str) str

Broadcast pre-signed transaction to the network :param tx_hex: The transaction hex string :return: The transaction hash

get_address() str

Get the address of the current wallet.

Returns:

The address

Return type:

str

async get_balance(address: str = '', **kwargs) List[CryptoAmount]

Get the balance of the wallet. If the address is not provided, the balance of the current wallet is returned.

Parameters:

address – The address (default is the address of the wallet)

Returns:

List of CryptoAmount, typically one element for BCH

Return type:

List[CryptoAmount]

async get_fees() FeeProgressive

Get default fees. No API call is performed.

Returns:

FeeProgressive object with average, fast, and fastest fees

get_private_key_bitcash() PrivateKey | PrivateKeyTestnet

Get the private key in bitcash format.

Returns:

The private key

Return type:

Union[PrivateKey, PrivateKeyTestnet]

get_public_key() bytes

Get the public key as bytes.

Returns:

The public key

Return type:

bytes

async get_transaction_data(tx_id: str) XcTx | None

Get transaction details by hash.

Parameters:

tx_id – The transaction hash

Returns:

Optional[XcTx]

async get_transactions(address: str = '', offset: int = 0, limit: int = 10, start_time: datetime | None = None, end_time: datetime | None = None, asset: Asset | None = None) TxPage

Get transactions of the wallet.

Parameters:
  • address – The address (default is the address of the wallet)

  • offset – The offset (ignored)

  • limit – The limit (ignored)

  • start_time – The start time (ignored)

  • end_time – The end time (ignored)

  • asset – The asset (ignored)

Returns:

The transaction page

async get_utxos(address='') List[UTXO]

Get the unspent transaction outputs (UTXOs) of the address.

Parameters:

address – address (default is the address of the wallet)

Returns:

list of UTXOs

Return type:

List[UTXO]

async transfer(what: CryptoAmount, recipient: str, memo: str | None = None, gas: Gas | None = None, check_balance: bool = True, **kwargs) str

Transfer the asset to the recipient address.

Parameters:
  • what – The amount to transfer

  • recipient – The recipient address

  • memo – The memo (optional)

  • gas – The gas options

  • check_balance – Whether to check the balance before transferring

  • kwargs – The additional parameters

Returns:

The transaction hash

validate_address(address: str) bool

Validate the BCH address

Parameters:

address (str) – Address to validate

Returns:

True if the address is valid, False otherwise

Return type:

bool

Bitcoin Cash constants

xchainpy2_bitcoincash.const.AssetTestBCH = ('BCH', 'TBCH', '', AssetKind.NATIVE)

Testnet BCH asset

xchainpy2_bitcoincash.const.BCH_BLOCKCHAIR_EXPLORER = ('https://blockchair.com/bch/', 'https://blockchair.com/bch/address/{address}', 'https://blockchair.com/bch/transaction/{tx_id}')

Blockchair explorer for Bitcoin Cash mainnet

xchainpy2_bitcoincash.const.BCH_BLOCKCHAIR_TESTNET_EXPLORER = ('https://blockchair.com/bch-testnet/', 'https://blockchair.com/bch-testnet/address/{address}', 'https://blockchair.com/bch-testnet/transaction/{tx_id}')

Blockchair explorer for Bitcoin Cash testnet

xchainpy2_bitcoincash.const.BCH_DECIMAL = 8

Bitcoin Cash decimal places

xchainpy2_bitcoincash.const.BCH_DEFAULT_FEE_BOUNDS = (1, 500)

Default fee bounds for Bitcoin Cash in sat/byte

xchainpy2_bitcoincash.const.DEFAULT_BCH_EXPLORERS = {NetworkType.MAINNET: ('https://blockchair.com/bch/', 'https://blockchair.com/bch/address/{address}', 'https://blockchair.com/bch/transaction/{tx_id}'), NetworkType.STAGENET: ('https://blockchair.com/bch/', 'https://blockchair.com/bch/address/{address}', 'https://blockchair.com/bch/transaction/{tx_id}'), NetworkType.TESTNET: ('https://blockchair.com/bch-testnet/', 'https://blockchair.com/bch-testnet/address/{address}', 'https://blockchair.com/bch-testnet/transaction/{tx_id}')}

Default explorers for Bitcoin Cash

xchainpy2_bitcoincash.const.DEFAULT_BCH_FEE_RATE = 1

Default fee rate for Bitcoin Cash in BCH satoshis per byte.

xchainpy2_bitcoincash.const.DEFAULT_PROVIDER_NAMES = []

Default provider names for Bitcoin Cash. Not used at the moment

xchainpy2_bitcoincash.const.MAX_MEMO_LENGTH = 80

Maximum memo length for Bitcoin Cash

xchainpy2_bitcoincash.const.ROOT_DERIVATION_PATHS = {NetworkType.MAINNET: "m/44'/145'/0'/0/", NetworkType.STAGENET: "m/44'/145'/0'/0/", NetworkType.TESTNET: "m/44'/1'/0'/0/"}

Root derivation paths for Bitcoin Cash