1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
614 stars 204 forks source link

How to get balance of HDKey? #268

Closed crazypon closed 2 years ago

crazypon commented 2 years ago
def generate_new_btc_wallet(user_id: int, wallet_id: Union[float, int]):
    config = configparser.ConfigParser()
    config.read("bot.ini")
    k = HDKey(config["payments"]["wallet_privkey"], network="bitcoin")
    ck = k.child_public(2235, network="bitcoin")
    address = ck.address()
    return address

I want to get a balance of HDKey, or get information about transaction using transaction hash. How can I do this?

crazypon commented 2 years ago

How can I create HDKey in the testnet network?

mccwdev commented 2 years ago

With the Service class you can retrieve transaction, utxo and balance information for a specific address. See documentation at https://bitcoinlib.readthedocs.io/en/latest/source/bitcoinlib.services.services.html#bitcoinlib.services.services.Service

And https://github.com/1200wd/bitcoinlib/blob/master/examples/services.py for some examples