首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sendSignedTransaction上的JSONRPC错误

sendSignedTransaction上的JSONRPC错误
EN

Ethereum用户
提问于 2018-05-18 08:23:15
回答 1查看 1.8K关注 0票数 1

我经营甘纳奇、松露和面膜。如果运行下面的代码,就会得到this.web3.eth.sendSignedTransaction()函数上的一个错误:

编辑:将我的代码更改为..然而,错误仍然没有改变。

代码语言:javascript
复制
    const encoded_tx = this.contract.methods.createCountry("NL", 100, 100, 100000000, this.account).encodeABI();
    const nonce = await this.web3.eth.getBlockTransactionCount(this.account);
    const rawTx = {
        nonce: this.utils.toHex(nonce), 
        gasLimit: this.utils.toHex(3000000),
        gasPrice: this.utils.toHex(this.utils.toWei('20', 'gwei')),
        data: encoded_tx,
        from: this.account,
        to: this.contractAddress
    };

    let tx = new Tx(rawTx);
    tx.sign(this.pvtKey);

    let serializedTx = tx.serialize();
    this.web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
    .on('receipt', console.log);

错误如下:

代码语言:javascript
复制
index.js:2178 Error: Returned error: {"id":6,"jsonrpc":"2.0","error":{"code":-32603}}
at Object.ErrorResponse (errors.js:29)

我完全不知道该去哪里看看,感觉好像我什么都试过了,这可能和我和元问题有关联这一事实有关吗?当我试图使用eth.method.send()通过元问询发送此事务时,事务不会给出错误,并且会按照预期的行为。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-05-18 14:16:58

要获得现在的信息,您必须调用web3.eth.getTransactionCount,而不是getBlockTransactionCount

  • getTransactionCount获取从该地址发送的事务数。
  • getBlockTransactionCount返回给定块中的事务数。

要调试使用ganache的交互,您可以从ganache-cli --verbose开始,它将显示客户机之间的交互,一个ganache,并显示有关事务的更多细节。

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

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

复制
相关文章

相似问题

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