Is there a PHP script where it validates a bitcoin private key and also gets the public address from the key?

My goal was to:

  1. verify the private key
  2. Get the public address using that private key
  3. Check the balance using an external api
  4. Sweep if balance > 0

I know I can test it by sending some bitcoins to it, or use electrum to attempt the sweep, but let's say I have 100 private keys I need to verify, how would I go about that?

  • What do you define as a valid private key in step 1.? When the key is in the secp256k1 ECDSA range? That would be nearly all 256-bit numbers. (en.bitcoin.it/wiki/…)
    – 0xb10c
    Jul 5, 2018 at 14:31
  • What format do your private keys have?
    – 0xb10c
    Jul 5, 2018 at 14:59
  • 1
    Question title edit: How do I empty the accounts of 100 people who's private keys I've hacked
    – JBaczuk
    Jul 10, 2018 at 14:48

1 Answer 1


No MVP PHP code, but some bits that could help.

  1. verify the private key

Assuming you want a private key to be in the secp256k1 ECDSA range. You could check if the key is any number between 0x1 and 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140. Take a look in the bitcoin wiki entry to private keys about the key range.

  1. Get the public address using that private key

The library BitcoinECDSA.php could help you out here. Especially


3 + 4.Check the balance using an external api and sweep if balance > 0

This step can be easily combined. If you want to rely on a third party you could use the Block.io PHP API and Libary. They have an example PHP code for sweeping.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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