0

While sending a raw transaction to rinkeby to deploy a contract, getting a transaction hash but in rinkeby etherscan.io it is showing the txHash as an invalid string. Here is my code :

web3.eth.getTransactionCount(account1, (err, txCount)=>{

//build the transaction
 const txObject = {
     nonce: web3.utils.toHex(txCount),
     gasLimit: web3.utils.toHex(1000000),
     gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
     data: data
 }
 //Sign the transaction
 const tx = new Tx(txObject)
 tx.sign(privateKey1)

 const serializedTransaction = tx.serialize()
 const raw = '0x' + serializedTransaction.toString('hex')

 //Broadcast the transaction
 web3.eth.sendSignedTransaction(raw, (err, txHash)=> {
     console.log('err:', err, 'txHash:', txHash)
  })
 })
  • 1
    Refer the following question ethereum.stackexchange.com/questions/50042/… – Soham Lawar Sep 20 '18 at 7:11
  • tx.serialize() <-- what is this? do you have the source for the function? Ethereum transactions are first signed, then RLP encoded, and then converted to hex. – Nulik Sep 20 '18 at 13:21
  • tx.serialize() is for RLP encoding only.The bytecode of the contract is stored in data variable in txObject and yes I have signed the transaction first then encoded it and then converted it into hex. @Nulik – crypto S. Sep 21 '18 at 6:15
0

There was an error in my smart contract due to which it was not getting deployed and giving invalid transaction hash. Now as I corrected the error I was able to deploy the contract.

0

if you deploy a new contract, the txObject should add "from: address". https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html?highlight=deploy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.