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)
  })
 })
Soham Lawar
  • 2,567
  • 14
  • 38
crypto S.
  • 345
  • 8
  • 17
  • 1
    Refer the following question https://ethereum.stackexchange.com/questions/50042/why-does-sendsignedtransaction-return-a-tx-hash-but-does-not-post-to-the-rinkeby – Soham Lawar Sep 20 '18 at 07: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 06:15

2 Answers2

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.

crypto S.
  • 345
  • 8
  • 17
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

Troublechain
  • 3
  • 1
  • 4