How do I get to the value in the 'scriptPubKey' part of the transaction ? shows a great example of going from address to scriptPubKey.

I'd like to do something similar: go from private key (ECDSA) to address. How do I do that? References to libs or code, as in the above question, would be appreciated.


From a privatekey (ECC, 32Byte) to an P2PKH address:

  1. Ensure the private key is a valid ECC privat key (libsecp256k1 function)
  2. Calculate the public key from the private key (complex math. function, use a library)
  3. Calculate the RIPEMD160 hash (aka Hash160) from the public key
  4. Do a base58check encoding of the hash160 with a prefix byte 0x00 (for mainnet) or 0x6f for testnet

C code to explore: https://github.com/libbtc/libbtc/blob/3331ec47ca4ad33e8f2e46e6f01dfbeae090c53d/src/toolfunc.c#L22


This may be of help, assuming you're fine with PHP code.


Not the answer you're looking for? Browse other questions tagged or ask your own question.