How to get bitcoin address of any private key?

2

calling bitcoin-cli dumpwallet returns wallet private keys and addresses.

Example

L34D2hAS9KBJQzJkHtmNt1bdSJ18cQUvfSnJEqPKH2oUj6sBxvXt 2017-11-23T05:11:13Z reserve=1 # addr=1D2mnuj9qeRAzmw8mjLDciyvqzQiiYZCfE hdkeypath=m/0'/0'/1030'

Importing this private key to wallet using importprivkey command returns null on success.

How to get bitcoin address related to this private key? or is there's any way get this private key details like balance or addresses?

Adam

Posted 2017-11-28T07:23:34.000

Reputation: 3 215

You could use an online wallet like https://blockchain.info/wallet/#/.

Oliver 2017-11-28T10:20:57.887

Thanks but i'm looking for a solution on bitcoin-core. if you got any idea how blockchain is getting these info it would be great.Adam 2017-11-28T11:20:06.107

Answers

2

the private key is a Private Key WIF Compressed, 52 characters base58, and can be used to convert into (compressed or uncompressed) public keys. These pub keys are usually hex codes, and can be converted into bitcoin addresses: 1D2mnuj9qeRAzmw8mjLDciyvqzQiiYZCfE and 1KWvNZB4Gf2Kars88aGR2cedUb81Q6gZKC. There is no easy way I am aware of to do this in bitcoin client.

Looking at the line you provided, the bitcoin address is behind the comment sign (#), and is part of a HD key, which complicates things even more, if I had to explain it. To understand the whole idea behind keys, you may want to read bitcoin.org or the book af Andreas "Mastering Bitcoin" (online available).

Looking then at e.g. blockchain.info, you can provide the addresses or the keys, and see that there is no value.

Hint: never ever (!) use this key again to transfer values. It has been disclosed, and people are only waiting to snipe the values from this address! - me too :-)

pebwindkraft

Posted 2017-11-28T07:23:34.000

Reputation: 4 568

So is it possible to generate more than one address using same private key?Adam 2017-11-28T12:12:53.093

yes. A priv key alone can already generate two pubkeys (compressed and uncompressed). And HD wallets: just a short extract from the book: "HD wallets contain keys derived in a tree structure, such that a parent key can derive a sequence of children keys, each of which can derive a sequence of grandchildren keys, and so on, to an infinite depth".pebwindkraft 2017-11-28T12:17:04.210

Thanks for your answer, I would be happy to get this book!Adam 2017-11-28T12:20:06.190

here: http://chimera.labs.oreilly.com/books/1234000001802/ and there is somewhere already the second edition (don't have the link ...)

pebwindkraft 2017-11-28T12:20:55.607

0

using PHP and Bitcoin-PHP library, we can do the following to get Bitcoin address of any private key:

        try {
            $master = PrivateKeyFactory::fromWif($key);
        } catch (\Exception $e) {
            echo "Invalid Address";
        }

        $BitcoinAddress = $master->getPublicKey()->getAddress()->getAddress();

        echo $BitcoinAddress;

Adam

Posted 2017-11-28T07:23:34.000

Reputation: 3 215