I’m using Laravel and trying to work with Solana block chain
When I try to generate a wallet address I got the address right but the private key is not formatted correctly
This is my function below
public function generateWallet() {
try {
// Initialize the curve and generator
$adapter = EccFactory::getAdapter(); $generator = EccFactory::getNistCurves()->generator256();
// Generate private key
$privateKey = $generator->createPrivateKey();
// Generate public key
$publicKey = $privateKey->getPublicKey();
// Serialize keys to DER format
$privateKeySerializer = new DerPrivateKeySerializer($adapter);
$publicKeySerializer = new DerPublicKeySerializer();
$privateKeyDer = $privateKeySerializer->serialize($privateKey);
$publicKeyDer = $publicKeySerializer->serialize($publicKey);
// Base58 encode the 32-byte public key
$publicKeyBytes = str_pad(gmp_export($publicKey->getPoint()->getX()), 32, "", STR_PAD_LEFT);
$base58 = new Base58();
$walletAddress = $base58->encode($publicKeyBytes);
return [
'private_key' => bin2hex($privateKeyDer),
'public_key' => bin2hex($publicKeyDer),
'address' => $walletAddress
];
} catch (Throwable $th) {
return [$th->getMessage()];
}
}
I want to get a correct private key which I can then use it to connect a wallet, send transactions and stuff like this
I tried to ask chatgpt but no helpful answer