Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Web3js signTransation

I am following the documentation to be able to sign and send a transaction on the Kovan testnet. I am currently getting an undefined value when I console out the txHash.

web3.eth.getTransactionCount(account1, (err, txCount) => {
    // 1)Build Transaction
    const txObject = {
        nonce: web3.utils.toHex(txCount),
        to: account2,
        value: web3.utils.toHex(web3.utils.toWei('0.05', 'ether')),
        gasLimit: web3.utils.toHex(2100),
        gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
    }
    
     // 2)Sign Transaction
    const tx = new Tx(txObject,{'chain':42})
    tx.sign(privateKey1)
    
    const serializedTransaction = tx.serialize()
    const raw = '0x' + serializedTransaction.toString('hex')

    console.log("raw:", raw)
    console.log("tx:", serializedTransaction)

    // 3)Broadcast Transaction
    web3.eth.sendSignedTransaction(raw, (err, txHash) =>{
        console.log('txHash:', txHash)
    })
    // COMMENTED-OUT web3.eth.sendSignedTransaction('0x' + serializedTransaction .toString('hex'))
    // .on('receipt', console.log);
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

signTransaction() only performs the signature. It doesn't broadcast the (signed) transaction to the network.

For that, you can use sendSignedTransaction() (docs), which submits the (signed and serialized) tx data to the provider, and the provider broadcasts it to the network.

web3.eth.sendSignedTransaction(signedTx.rawTransaction)
.on('receipt', console.log);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda