Package: xchainpy-binance
xchainpy/xchainpy_binanceBinance Module for XChainPy ClientsModulesclient- Custom client for communicating with binance_chainmodels- model wrapper for binance_chain typesutil- Utitilies for using binance_chainFollowing dependencies have to be installed into your projectsecp256k1Crypto - py-binance-chain - pywallet - mnemonicpipinstallxchainpy_binanceBinance Client moduleInitialize a clientfromxchainpy_client.models.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClient# Note: This phrase is created by https://iancoleman.io/bip39/ and will never been used in a real-worldphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Mainnet,phrase=phrase))# if you want to change phrase after initialize the clientclient.set_phrase('wheel leg dune emerge sudden badge rough shine convince poet doll kiwi sleep labor hello')# if you want to change network after initialize the clientawaitclient.purge_client()client.set_network(Network.Mainnet)# get python-binance-chain clientclient.get_bnc_client()# when you are done with the client, call thisawaitclient.purge_client()Address methodsfromxchainpy_client.models.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClientphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Mainnet,phrase=phrase))address=client.get_address()is_valid=client.validate_address(address)# boolprint(address)print(is_valid)Feesfromxchainpy_client.models.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClientphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Mainnet,phrase=phrase))fees=awaitclient.get_fees()multi_send_fees=awaitclient.get_multi_send_fees()single_and_multi_fees=awaitclient.get_single_and_multi_fees()print(f'''fees:average:{fees.average}fast:{fees.fast}fastest:{fees.fastest}\n''')print(f'''multi_send_fees:average:{multi_send_fees.average}fast:{multi_send_fees.fast}fastest:{multi_send_fees.fastest}\n''')print(f'''single_and_multi_fees:single:average:{single_and_multi_fees['single'].average}fast:{single_and_multi_fees['single'].fast}fastest:{single_and_multi_fees['single'].fastest}multi:average:{single_and_multi_fees['single'].average}fast:{single_and_multi_fees['single'].fast}fastest:{single_and_multi_fees['single'].fastest}''')Balancefromxchainpy_client.models.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClientphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Testnet,phrase=phrase))address=client.get_address()account=awaitclient.get_account(address=address)balances=awaitclient.get_balance(address=address)forbalanceinbalances:print(f'asset:{balance.asset}, amount:{balance.amount}')Transactions and Transaction_datafromxchainpy_client.models.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClientfromxchainpy_client.models.tx_typesimportTxHistoryParamsphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Testnet,phrase=phrase))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.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClientfromxchainpy_client.models.tx_typesimportTxParamsfromxchainpy_util.assetimportAssetBTCphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Testnet,phrase=phrase))address=client.get_address()params=TxParams(asset=AssetBNB,amount=0.0001,recipient=address,memo='memo')tx_hash=awaitclient.transfer(params)print(tx_hash)Explorer urlfromxchainpy_client.models.typesimportNetwork,XChainClientParamsfromxchainpy_binance.clientimportClientfromxchainpy_client.models.tx_typesimportTxParamsphrase='rural bright ball negative already grass good grant nation screen model pizza'client=Client(XChainClientParams(network=Network.Testnet,phrase=phrase))print(client.get_explorer_url())print(client.get_explorer_address_url('testAddressHere'))print(client.get_explorer_tx_url('testTxHere'))awaitclient.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'))Crypto modulefrompy_binance_chain.environmentimportBinanceEnvironmentfromxchainpy_binanceimportcrypto# Note: This phrase is created by https://iancoleman.io/bip39/ and will never been used in a real-worldphrase='rural bright ball negative already grass good grant nation screen model pizza'env=BinanceEnvironment.get_testnet_env()seed=crypto.mnemonic_to_seed(mnemonic=phrase)print(seed)private_key=crypto.mnemonic_to_private_key(mnemonic=phrase,index=0,env=env)print(private_key)public_key=crypto.private_key_to_public_key(private_key=private_key)print(public_key)address=crypto.private_key_to_address(private_key=private_key,prefix='tbnb')print(address)address=crypto.public_key_to_address(public_key=public_key,prefix='tbnb')print(address)is_valid=crypto.check_address(address=address,prefix='tbnb')print(is_valid)TestsThese packages needed to run tests:pytestpip install pytestpytest-asynciopip install pytest-asyncioHow to run test ?$python-mpytestxchainpy/xchainpy_binance/tests