bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.71k stars 2.11k forks source link

Need help with the generate wallet address and private key #2177

Closed AmaarHassanCS closed 1 month ago

AmaarHassanCS commented 1 month ago

Hi,

I am very new to blockchain and crypto and i used this library to generate a wallet address and its private key.

Here is the code for that ` // Generate a mnemonic (12 words) const generateMnemonic = () => { const mnemonic = bip39.generateMnemonic(); console.log("Mnemonic:", mnemonic); return mnemonic; };

// Generate a wallet from the mnemonic const generateWalletAddressDetails = async (mnemonic) => { try { const seed = await bip39.mnemonicToSeed(mnemonic); const root = BIP32.fromSeed(seed); const child = root.derivePath("m/44'/0'/0'/0/0"); // Standard BIP44 path

// Generate the Bitcoin address
const walletDetails = bitcoin.payments.p2pkh({ pubkey: child.publicKey });
const privateKey = child.toWIF();

return {
  privateKey,
  ...walletDetails
};

} catch (error) { console.error(error); } };`

I eventually get something like "address": "14EuxgtJkwi8e59QUzanaajiRB2VaTb86y", "privateKey": "L5kG1bxKLfmVMw29Rxa7xzX8DSfULr1M2iiEA2LbwmijU8cBrYnC",

My query is really dumb...How can i use the above, or is it even possible, to use the generated address to send and receive funds in a BTC wallet?

Your help will be much appreciated! Thanks

jasonandjay commented 1 month ago

Your private key and account address are fine, you can use this method to generate the account you need to use

However, if you have not yet mastered how to sign, it is not recommended that you use scripts to operate the account.

You can use a common wallet on the market