jimmysong / programmingbitcoin

Repository for the book
Other
1.75k stars 656 forks source link

Chapter 4 Exercise 9 Code returns invalid testnet address #253

Closed alexbarron closed 2 years ago

alexbarron commented 2 years ago

I'm trying to generate a testnet address and send testnet BTC to myself through https://testnet-faucet.mempool.co/ but it's returning an invalid testnet error. I checked my code against the answer code and it's the same. In fact, even the testnet address listed in the answer for this exercise is returning invalid on that site. I'm also trying Jimmy's passphrase from the book and the code returns a different address than his in the book but both give me the same invalid testnet address error.

Anyone else encounter something like this? My tests are all passing. And here is my code for generating the testnet address:

from ecc import PrivateKey
from helper import hash256, little_endian_to_int

passphrase = b'jimmy@programmingbitcoin.com my secret'
secret = little_endian_to_int(hash256(passphrase))
priv = PrivateKey(secret)
address = priv.point.address(testnet=True)
print(address)
def little_endian_to_int(b):
    '''little_endian_to_int takes byte sequence as a little-endian number.
    Returns an integer'''
    # use int.from_bytes()
    return int.from_bytes(b, 'little')
vvronskyFX commented 2 years ago

That's interesting. I went through this section no problem.

Looks like you defined "address". For my code, I just printed like this: print(priv.point.address(testnet=True))

Would that make a difference in your solution?

alexbarron commented 2 years ago

I confirmed it was just an issue with that particular testnet faucet. Putting in their own tBTC donation address also returns invalid! I tried another testnet faucet and everything worked fine. Here's the one I used: https://bitcoinfaucet.uo1.net/

In case that one goes down as well, here's a list of several faucet options: https://support.keys.casa/hc/en-us/articles/360047997611-Testnet-Bitcoin-TBTC-

Gaming32 commented 5 months ago

I am having this same issue, except that the site you referenced is also giving me an error. However, their own donation address returns valid. One thing I'm noticing is that the addresses generated from this code are shorter than the donation address.