首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sendRawTransaction给出了无效的txHash

sendRawTransaction给出了无效的txHash
EN

Ethereum用户
提问于 2018-09-20 06:39:25
回答 2查看 377关注 0票数 0

在向rinkeby发送原始事务以部署合同时,获取事务哈希,但在rinkeby etherscan.io中,它将txHash显示为无效字符串。这是我的代码:

代码语言:javascript
复制
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)
  })
 })
EN

回答 2

Ethereum用户

回答已采纳

发布于 2018-09-21 05:48:39

在我的智能契约中出现了一个错误,因为它没有被部署,并且给出了无效的事务哈希。现在,当我更正错误时,我能够部署契约。

票数 0
EN

Ethereum用户

发布于 2018-09-21 07:37:22

如果您部署了一个新合同,txObject应该添加"from: address“。https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html?highlight=deploy

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/59121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档