loading...

How to get bitcoin address and its privatekey?

ishwar profile image ishwar chandra tiwari ・1 min read

I have generated bitcoin address using bitcoinjs library see below code

return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address

The above code returns address see below
1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T

But for signing raw transaction I need privatekey of this address 1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T

What should I do to get address and its privatekey?

I now how to generate address using derivation path from mnemonic.
For derivation path m/44'/0/0/0 I is generated 1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T address.
Now I need to now how can get privatekey for this derivation path m/44'/0/0/0

Discussion

pic
Editor guide
 

I think you have some conception misunderstanding here. The bitcoin address is just a hash of a public key in base58 encoding. You can't generate a private key from an address because a hash function is a one-way function. You can't even generate a public key from an address for the same reason.

The right flow would be:

  1. You somehow retrieve your keypair (public and private keys) - maybe you had one before or maybe you've just generated it.
  2. You generate a hash of a public key - it is your bitcoin address now.
  3. The keypair is used to sign your transactions, so everybody can cryptographically verify it.
  4. The address is just a handy nym for your public key - it has fixed length and everybody can generate it from your public key.
 

I think you didn't get my question, My question was is there any method to get privatekey
For Example i generated an address using below method

bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address

but for signing raw transaction I need privatekey of this address 1FYtPnUZZ2ZJL2fZ6XehGtkHfujUHkqK3T

This is what i am asking, What should I do to get address and its privatekey?