Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to print private and public key #45

Open
kroszkak opened this issue Feb 22, 2021 · 1 comment
Open

how to print private and public key #45

kroszkak opened this issue Feb 22, 2021 · 1 comment

Comments

@kroszkak
Copy link

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;
}`

@rgex
Copy link
Contributor

rgex commented Feb 25, 2021

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants