Package: xchainpy-bitcoincash
xchainpy/xchain-bitcoincashBitcoin-Cash Module for XChainPy ClientsModulesclient- Custom client for communicating with bitcash , haskoin apimodels- Model wrapper for bitcoin-cash and haskoin required typesutil- Utitilies for using bitcash and haskoinFollowing dependencies have to be installed into your projectbitcash - cashaddress - mnemonic - bip_utilsService ProvidersThis package uses the following service providers:FunctionServiceNotesBalancesHaskoinhttps://api.haskoin.com/#/Address/getBalanceTransaction historyHaskoinhttps://api.haskoin.com/#/Address/getAddressTxsFullTransaction details by hashHaskoinhttps://api.haskoin.com/#/Transaction/TransactionTransaction feesBitgohttps://app.bitgo.com/docs/#operation/v2.tx.getfeeestimateTransaction broadcastbitcore.iohttps://api.bitcore.ioExplorerBlockchain.comhttps://www.blockchain.comHaskoin API rate limits: NoBitgo API rate limits:https://app.bitgo.com/docs/#section/Rate-Limiting(10 requests/second)Installationpipinstallxchainpy_bitcoincashBefore install the package on M1 Mac, execute these commands:brewinstallgmpopenblasopensslautoconfautomakelibffilibtoolpkg-configCFLAGS=-I/opt/homebrew/opt/gmp/includeLDFLAGS=-L/opt/homebrew/opt/gmp/libpip3installfastecdsaCFLAGS=-I$(brew--prefixopenssl)/includeLDFLAGS=-L$(brew--prefixopenssl)/libpip3installscryptexportOPENBLAS="$(brew--prefixopenblas)$OPENBLAS"Bitcoincash Client moduleInitialize a clientfromxchainpy_client.models.typesimportNetworkfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParams# Note: This phrase is created by https://iancoleman.io/bip39/ and will never been used in a real-worldphrase='atom green various power must another rent imitate gadget creek fat then'client=Client(BitcoincashClientParams(phrase=phrase,network=Network.Testnet))# if you want to change phrase after initialize the clientclient.set_phrase('caution pear excite vicious exotic slow elite marble attend science strategy rude')# if you want to change network after initialize the clientclient.purge_client()client.set_network(Network.Mainnet)# when you are done with the client, call thisclient.purge_client()Address methodsfromxchainpy_client.models.typesimportNetworkfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParamsphrase='atom green various power must another rent imitate gadget creek fat then'client=Client(BitcoincashClientParams(phrase=phrase,network=Network.Testnet))address=client.get_address()is_valid=client.validate_address(address)# boolprint(address)print(is_valid)# change indexaddress=client.get_address(1)is_valid=client.validate_address(address)# boolprint(address)print(is_valid)Feesfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParamsclient=Client(BitcoincashClientParams())# Get feeRate estimationsfee_rates=awaitclient.get_fee_rates()# Get fee estimationsfees=awaitclient.get_fees()# Get fee estimations with memomemo='SWAP:THOR.RUNE'fees_with_memo=awaitclient.get_fees(memo)print(f'''fee rates:average:{fee_rates.average}fast:{fee_rates.fast}fastest:{fee_rates.fastest}\n''')print(f'''fees:average:{fees.average}fast:{fees.fast}fastest:{fees.fastest}\n''')print(f'''fees with memo:average:{fees_with_memo.average}fast:{fees_with_memo.fast}fastest:{fees_with_memo.fastest}\n''')Balancefromxchainpy_client.models.typesimportNetworkfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParamsphrase='atom green various power must another rent imitate gadget creek fat then'client=Client(BitcoincashClientParams(phrase=phrase,network=Network.Testnet))address=client.get_address()balance=awaitclient.get_balance(address=address)balance=balance[0]print(f'asset:{balance.asset}, amount:{balance.amount}')Transactions and Transaction_datafromxchainpy_client.models.tx_typesimportTxHistoryParamsfromxchainpy_client.models.typesimportNetworkfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParamsphrase='atom green various power must another rent imitate gadget creek fat then'client=Client(BitcoincashClientParams(phrase=phrase,network=Network.Testnet))address=client.get_address()params=TxHistoryParams(address=address,limit=1)transactions=awaitclient.get_transactions(params)# type of transactions is xchainpy_client.models.tx_types.TxPaget=transactions.txs[0]print(t.asset)print(t.tx_from[0].amount)print(t.tx_from[0].address)print(t.tx_to[0].amount)print(t.tx_to[0].address)print(t.tx_date)print(t.tx_type)print(t.tx_hash)transaction=awaitclient.get_transaction_data(t.tx_hash)# transaction object is equal by t objectTransferfromxchainpy_client.models.typesimportNetworkfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParams,BitcoincashTxParamsphrase='atom green various power must another rent imitate gadget creek fat then'client=Client(BitcoincashClientParams(phrase=phrase,network=Network.Testnet))address=client.get_address()params=BitcoincashTxParams(amount=0.0000001,recipient=address,memo='memo')tx_hash=awaitclient.transfer(params)print(tx_hash)Explorer urlfromxchainpy_client.models.typesimportNetworkfromxchainpy_bitcoincash.clientimportClientfromxchainpy_bitcoincash.models.client_typesimportBitcoincashClientParamsclient=Client(BitcoincashClientParams())print(client.get_explorer_url())print(client.get_explorer_address_url('testAddressHere'))print(client.get_explorer_tx_url('testTxHere'))client.purge_client()client.set_network(Network.Mainnet)print(client.get_explorer_url())print(client.get_explorer_address_url('testAddressHere'))print(client.get_explorer_tx_url('testTxHere'))TestsThese packages needed to run tests:pytestpip install pytestpytest-asynciopip install pytest-asyncioHow to run test ?$python-mpytestxchainpy/xchainpy_bitcoincash/tests