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
613 stars 204 forks source link

Invalid Addresses? #398

Closed MarcoDotIO closed 6 months ago

MarcoDotIO commented 6 months ago

Hello there,

I am having some issues with creating valid Bitcoin addresses with the given SDK. Here is my test code:

from bitcoinlib.wallets import *

w1 = wallet_create_or_open(
            name="test2",
            network='testnet'
)

print("Wallet address: ", w1.get_key().address)

And any addresses from the get_key() function are not valid (e.g., they aren't prefixed with bc1 for mainnet, tb1 for testnet). Was something changed in a newer version?

Here's an example of the above output: mfvFzusKPZzGBAhS69AWvziRPjamtRhYpZ

MarcoDotIO commented 6 months ago

Update:

Seems like the documentation is out of date. Here's the way to derive valid bitcoin addresses:

from bitcoinlib.wallets import *

w1 = wallet_create_or_open(name="test2002", network='testnet')

pubkey = w1.get_key().key()

addr = Address("{pubkey}", encoding='bech32', script_type="p2wpkh", network="testnet")

print("Wallet address: ", addr.address)

Closing, but considering adding some additional documentation to clear things up.