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)
})
})
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:21tx.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