Discussion on: How to get bitcoin address and its privatekey?

seniorjoinu profile image

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.
ishwar profile image
ishwar chandra tiwari Author

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?