BitcoinECDSA.php icon indicating copy to clipboard operation
BitcoinECDSA.php copied to clipboard

how to print private and public key

Open kroszkak opened this issue 5 years ago • 1 comments

Hi, im basic. I need to print private and public key. I tried to use $bitcoinECDSA->getPrivateKey();, buto when i do this, the private key is not for generateg BTC address, but other. Can you help me?

Full code:

`require_once 'src/BitcoinPHP/BitcoinECDSA/BitcoinECDSA.php';

use BitcoinPHP\BitcoinECDSA\BitcoinECDSA;

$bitcoinECDSA = new BitcoinECDSA(); $bitcoinECDSA->generateRandomPrivateKey(); //generate new random private key $address = $bitcoinECDSA->getAddress(); //compressed Bitcoin address $p = $bitcoinECDSA->getPrivateKey(); echo "Address: " . $address . PHP_EOL;

//Validate an address (Verify the checksum) if($bitcoinECDSA->validateAddress($address)) { echo "The address is valid" . PHP_EOL; print $p . "

"; } else { echo "The address is invalid" . PHP_EOL; }`

kroszkak avatar Feb 22 '21 21:02 kroszkak

Your code looks correct although I did not run it. Instead of getting the private key in its Hex format you can also get it under its WIF format using $bitcoinECDSA->getWif();

rgex avatar Feb 25 '21 12:02 rgex