I want to understand how Ethereum works and i want to calculate the public key and wallet address from private key.
I have read this tutorial: https://piyopiyo.medium.com/generating-an-ethereum-wallet-with-an-existing-private-key-5cda690a8eb8
Here is the code:
var Wallet = require('ethereumjs-wallet');
var EthUtil = require('ethereumjs-util');
const privateKeyString = '0x...MyPrivateKey...';
const privateKeyBuffer = EthUtil.toBuffer(privateKeyString);
const wallet = Wallet.fromPrivateKey(privateKeyBuffer);
const publicKey = wallet.getPublicKeyString();
console.log(publicKey);
const address = wallet.getAddressString();
console.log(address);
It sounds great but i have this runtime error:
TypeError: Wallet.fromPrivateKey is not a function
I think this is because ethereumjs-wallet has changed in the latest versions. But how can i load a private key with latest version ?
Thanks
const wallet = Wallet.fromPrivateKey(privateKeyBuffer);
generates "TypeError: Wallet.fromPrivateKey is not a function"