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

correção #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//importando as dependencias
/* importando as dependencias
const bip32 = require('bip32')
const bip39 = require('bip39')
const bitcoin = require('bitcoinjs-lib')
Expand Down Expand Up @@ -30,4 +30,90 @@ let btcAddress = bitcoin.payments.p2pkh({
console.log("Carteira gerada")
console.log("Endereço: ", btcAddress)
console.log("Chave privada:", node.toWIF())
console.log("Seed:", mnemonic)
console.log("Seed:", mnemonic)

*/

// CÓDIGO FUNCIONOU PARA MIM 2024 ABAIXO

// Importing dependencies

const bip32 = require('bip32');

const bip39 = require('bip39');

const bitcoin = require('bitcoinjs-lib');



// Define network parameters for Testnet4

const testnet4 = {

messagePrefix: '\x18Bitcoin Signed Message:\n',

bech32: 'tb',

bip32: {

public: 0x043587cf, // Base58 prefix for xpub on Testnet4

private: 0x04358394 // Base58 prefix for xprv on Testnet4

},

pubKeyHash: 0x6f, // P2PKH starts with 'm' or 'n'

scriptHash: 0xc4, // P2SH starts with '2'

wif: 0xef // Wallet Import Format prefix

};



// HD wallets derivation path for Testnet4

const path = `m/49'/1'/0'/0`;



// Generating mnemonic (seed phrase)

let mnemonic = bip39.generateMnemonic();

const seed = bip39.mnemonicToSeedSync(mnemonic);



// Creating HD wallet root from the seed

let root = bip32.fromSeed(seed, testnet4);



// Deriving account and generating address

let account = root.derivePath(path);

let node = account.derive(0).derive(0);



let btcAddress = bitcoin.payments.p2pkh({

pubkey: node.publicKey,

network: testnet4,

}).address;



console.log("Carteira Criada por Testnet4");

console.log("Address: ", btcAddress);

console.log("Private Key: ", node.toWIF());

console.log("Seed Phrase: ", mnemonic);
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
* Sergioaero1 - Ótimo repositório

Entendi bem as partes importantes. na rática tive dificuldades. Pesquisei para encontrar os erros. Consegui um fork de um código funcionando. ele esta um pouco dierente do código desse curso, normal, as coisas atualizaram e oi bom para mim buscar atualização e ver o código funcionando.

Meu código estava dando erro na linha que deveria gerar o endereço da carteira.

* SEGUE O CÓDIGO QUE RESOLVEU MEU PROBLEMA 2024:

// Importing dependencies

const bip32 = require('bip32');

const bip39 = require('bip39');

const bitcoin = require('bitcoinjs-lib');



// Define network parameters for Testnet4

const testnet4 = {

messagePrefix: '\x18Bitcoin Signed Message:\n',

bech32: 'tb',

bip32: {

public: 0x043587cf, // Base58 prefix for xpub on Testnet4

private: 0x04358394 // Base58 prefix for xprv on Testnet4

},

pubKeyHash: 0x6f, // P2PKH starts with 'm' or 'n'

scriptHash: 0xc4, // P2SH starts with '2'

wif: 0xef // Wallet Import Format prefix

};



// HD wallets derivation path for Testnet4

const path = `m/49'/1'/0'/0`;



// Generating mnemonic (seed phrase)

let mnemonic = bip39.generateMnemonic();

const seed = bip39.mnemonicToSeedSync(mnemonic);



// Creating HD wallet root from the seed

let root = bip32.fromSeed(seed, testnet4);



// Deriving account and generating address

let account = root.derivePath(path);

let node = account.derive(0).derive(0);



let btcAddress = bitcoin.payments.p2pkh({

pubkey: node.publicKey,

network: testnet4,

}).address;



console.log("Carteira Criada por Testnet4");

console.log("Address: ", btcAddress);

console.log("Private Key: ", node.toWIF());

console.log("Seed Phrase: ", mnemonic);