首页 > 其他分享 >"the tx doesn't have the correct nonce":使用hardhat调用ganache上部署的合约遇到的一个错误

"the tx doesn't have the correct nonce":使用hardhat调用ganache上部署的合约遇到的一个错误

时间:2023-12-18 10:38:03浏览次数:21  
标签:nonce node await tx 存证 ganache correct

完整的报错
==================>查询存证请求
存证请求内容, datahash:0xaad2171441bd73b773e9a9e062753909360bdfcabbddbe93c6c58b13c5c0feaa, 创建人:0xF7A1938Fecc594aaF126d46fd173cE74A659ad9A, 附加信息:0x66656974757a6920616920646f756368757a69, 已投票:0n, 共需投票:2n
==================>存证请求需要两个以上地址vote

Error: could not coalesce error (error={ "code": -32000, "message": "the tx doesn't have the correct nonce. account has nonce of: 21 tx has nonce of: 20", "stack": "Error: the tx doesn't have the correct nonce. account has nonce of: 21 tx has nonce of: 20\n    at TransactionPool.prepareTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:122021)" }, payload={ "id": 23, "jsonrpc": "2.0", "method": "eth_sendRawTransaction", "params": [ "0x02f89182053914843b9aca008445c21fcc830123d8941ea80e037af8715c7837638e1f4ed6d729029a9380a4ab9beda7aad2171441bd73b773e9a9e062753909360bdfcabbddbe93c6c58b13c5c0feaac080a0d596794b96bd555c3cf682d7968e02e986a7bf00ee6064b9112833f19cbfa57ea0090e9ba12302f6ab20108e2e0ab16248bb5d99e130bffdbb4daa3b39ae129f92" ] }, code=UNKNOWN_ERROR, version=6.9.0)
    at makeError (C:\Users\linyang\evidence\node_modules\ethers\src.ts\utils\errors.ts:694:21)
    at JsonRpcProvider.getRpcError (C:\Users\linyang\evidence\node_modules\ethers\src.ts\providers\provider-jsonrpc.ts:1007:25)
    at C:\Users\linyang\evidence\node_modules\ethers\src.ts\providers\provider-jsonrpc.ts:527:45
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'UNKNOWN_ERROR',
  error: {
    message: "the tx doesn't have the correct nonce. account has nonce of: 21 tx has nonce of: 20",
    stack: "Error: the tx doesn't have the correct nonce. account has nonce of: 21 tx has nonce of: 20\n" +
      '    at TransactionPool.prepareTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:122021)',
    code: -32000
  },
  payload: {
    method: 'eth_sendRawTransaction',
    params: [
      '0x02f89182053914843b9aca008445c21fcc830123d8941ea80e037af8715c7837638e1f4ed6d729029a9380a4ab9beda7aad2171441bd73b773e9a9e062753909360bdfcabbddbe93c6c58b13c5c0feaac080a0d596794b96bd555c3cf682d7968e02e986a7bf00ee6064b9112833f19cbfa57ea0090e9ba12302f6ab20108e2e0ab16248bb5d99e130bffdbb4daa3b39ae129f92'
    ],
    id: 23,
    jsonrpc: '2.0'
  },
  shortMessage: 'could not coalesce error'
}
对应的Hardhat JavaScript代码
let evidenceContract = await new ethers.Contract(contractAddress, contractABI, provider);
let signer = await new ethers.Wallet("0x624cfb2cb9b9c3212abfa2800fd8de8e2501c84500336007f4459c50198c69f7", provider);
let evidenceContractConnected = await evidenceContract.connect(signer);
    //创建一个存证请求
    console.log("==================>新建存证请求");
    const ext = ethers.toUtf8Bytes("feituzi ai douchuzi");
    let txn = await evidenceContractConnected.createSaveRequest(sha256hash, ext);
    console.log("创建存证请求, 交易结果: %s", txn);
    await new Promise(r => setInterval(r, 1000));

    console.log("==================>查询存证请求");
    let request = await evidenceContractConnected.getRequestData(sha256hash);
    //bytes32, address creator, bytes memory ext, uint8 voted, uint8 threshold
    console.log("存证请求内容, datahash:%s, 创建人:%s, 附加信息:%s, 已投票:%s, 共需投票:%s", 
        request[0], request[1], request[2], request[3], request[4]);
    await new Promise(r => setInterval(r, 1000));

    //存证请求需要两个以上地址vote,第一个投票
    console.log("==================>存证请求需要两个以上地址vote");
    let result = await evidenceContractConnected.voteSaveRequest(sha256hash);
    console.log("%s对存证请求的投票结果%s", await signer.getAddress(), result);
    await new Promise(r => setInterval(r, 1000));
分析与解决

上面evidenceContractConnected是连了signer的合约对象,可以调用合约的写方法。然后在后面复用这个对象调用了多个方法,其中createSaveRequest,voteSaveRequest都是写方法。

the tx doesn't have the correct nonce. account has nonce of: 21 tx has nonce of: 20

上面这个报错意思是tx的nonce比account的落后1,google了一下都是建议两次调用之间加一下time wait,所以可以使用如下代码解决:

await new Promise(r => setInterval(r, 1000));

标签:nonce,node,await,tx,存证,ganache,correct
From: https://www.cnblogs.com/lyhero11/p/17910457.html

相关文章

  • Jmeter46 配置元件,读取.properties,.ini, .txt 配置文件,为全局做自动化
     配置元件主要是用与测试前的配置,将配置转换为变量设置到jmetercontext中。而jmeter默认并没有配置元件(.properties)读取器,但是由于jmeter是开源的,我们可以自己定义一个配置元件来读取配置文件。插件下载地址:https://www.testautomationguru.com/jmeter-property-file-reader-......
  • NVIDIA RTX4090,你能用它做什么?
    介绍什么是NVIDIARTX4090是一款先进的图形处理单元(GPU),它具有强大的性能和功能,可以用于多种用途。本文的二级标题将介绍NVIDIARTX4090的定义、特点、以及它在图形渲染、深度学习、虚拟现实等领域的应用。通过这些介绍,读者将能够全面了解NVIDIARTX4090的优势和潜力,以及它为用户提......
  • [20231213]tmux与环境变量PTAH.txt
    [20231213]tmux与环境变量PTAH.txt--//昨天给一台机器安装配置tmux,发现登陆tmux后环境变量PATH特别长,问题在于tmux登陆后要重复执行.bash_profile的内容.--//以前遇到过,主要问题在于.bash_profile在配置PATH时写法不合理.exportPATH=$PATH;...exportPATH=$PATH;...exportPAT......
  • 台达 通讯出现 DriverInf.txt文件丢失 方便别人
    DriverInf.txt文件丢失是因为计算机使用了mindmanager6免安装版本而把登入文件里面的msxmldll路径修改掉造成有使用到msxmlDLL的所有应用程序都会发生问题.下载链接:DownloadKB2758694:MicrosoftXMLCoreServices4.0ServicePack3安全性更新fromOfficialMicrosoft......
  • [20231207]开发不应该这样写sql4.txt
    [20231207]开发不应该这样写sql4.txt--//最近在优化sql语句,发现另外一种风格,实际上以前也遇到过,感觉这就像一种病,会传染只要一个这样写后面的要么跟进要么--//不改。我觉得开发应该感谢exadata,不然我们的生产系统估计会垮掉。1.环境:XXXXXX>@ver1PORT_STRING          ......
  • 英伟达显卡 RTX A4000 环境安装
    ​1.安装显卡驱动驱动下载地址: https://www.nvidia.cn/Download/Find.aspx?lang=cn此处下载的显卡驱动为(有的显卡型号可以选择cuda版本):NVIDIA-Linux-x86_64-470.182.03.run安装后,xshell中输入nvidia-smi显示:也就是说安装的cuda版本不能高于11.4 2.下载并安装minicon......
  • NVIDIA RTX4090,你能用它做什么?
    都说男生是世界上最简单的动物,为什么呢?举个例子,你要给女朋友送礼,你可以选择包、口红、护肤品、化妆品等,而包的品牌和样式、口红的色号等足以让你挑得眼花缭乱。而男生不一样,如果女生选择给男生送礼,我相信一块RTX4090就足以让他高兴得死去活来。RTX4090到底是何方神圣?它凭什么......
  • ETL-txt数据转换为Excel数据
    前言:  将txt文件中的数据抽取出来,然后装载到Excel中。 具体操作步骤:  数据准备id,name,age,gender,province,city,region,phone,birthday,hobby,register_date392456197008193000,张三,20,0,北京市,昌平区,回龙观,18589407692,1970-8-19,美食;篮球;足球,2018-8-69442......
  • 解决Visual Studio 2022升级到17.8之后,Visual AssistX功能OpenCorespondingFile快捷键
    冲突的命令是:Edit.IntelliCode.APIUsageExamples,这是v17.7的:  这是17.8的:  所以,解决方法就是在新版本中,将Edit.IntelliCode.APIUsageExamples的快捷键移除,并重新为VAssistX.OpenCorespondingFile添加Alt+O的全局快捷键即可。改好后可以在VAX的菜单中看到,如果没生效,......
  • 使用hardhat + ganache进行本地solidity开发
    hardhat是有本地开发网络的,但ganache是个有界面的程序,也是在本地模拟一个以太坊链,但是界面比较漂亮一些。hardhat.config.jsrequire("@nomicfoundation/hardhat-toolbox");/**@typeimport('hardhat/config').HardhatUserConfig*/module.exports={solidity:"0.8.19",......