错误:无法估计gas;交易可能会失败或可能需要手动气体限制SERVER_ERROR

问题描述 投票:0回答:1

我正在尝试在 WSL studio 和 Ganache 上使用 javascript 部署 SimpleStorage Solidity 合约。

我的deploy.js代码是:

const ethers = require("ethers");
const { readFileSync } = require("fs");
const fs = require("fs-extra");
async function main() {
  //
  const provider = new ethers.providers.JsonRpcProvider(
    "http://172.24.176.1:7545"
  );
  const wallet = new ethers.Wallet(
    "0x757b08fac160cc001a4adfebadc26ac10a6e59e2490fda35bce0c35939f265f1",
    provider
  );
  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf8"
  );
  const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  console.log("Deploying, please wait...");
  const contract = await contractFactory.deploy(); //STOP here wait for contract to deploy
  console.log(contract);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

我在终端上尝试了命令“node deploy.js”,出现以下错误:

root@LAPTOP-UFP1511I:~/folder/hh-fcc/ethers-simple-storage-fcc#节点deploy.js 正在部署,请稍候...

错误:无法估计gas;交易可能会失败或可能需要手动气体限制[请参阅:https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT](错误={“reason”:“处理响应错误”,“code”:“SERVER_ERROR”, "body":"{"id":49,"jsonrpc":"2.0","error":{"message":"处理事务时出现 VM 异常:无效操作码","stack":"RuntimeError: VM 异常处理交易:无效操作码 精确 (C:\Program Files\WindowsApps\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\app\resources\static\node\node_modules\ganache\dist\node\1.js:2:182136)","code":-32000, "name":"RuntimeError","data":{"hash":null,"programCounter":24,"result":"0x","reason":null,"message":"无效操作码"}}} ","错误":{"代码":-32000,"数据":{"哈希":null,"programCounter":24,"结果":"0x","原因":null,"消息":"无效操作码"}},"requestBody":"{"method":"eth_estimateGas","params":[{"type":"0x2","maxFeePerGas":"0xd09dc300","maxPriorityFeePerGas":"0x59682f00", "from":"0x08d5cb97517f8a7189b7b9f34ca26f554827179f","data":"0x608060405234801561000f575f80fd5b506108f28061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c80632e64cec1146100595780636057361d146100775780636f760f41146100935780638bab8dd5146100af5780639e7a13ad146100df575b5f80fd5b610061610110565b60405161006e919061029f565b60405180910390f35b610091600480360381019061008c91906102f3565b610118565b005b6100ad600480360381019

有人可以告诉我发生了什么事吗?

javascript blockchain solidity ethers.js ganache
1个回答
0
投票

尝试这些,选项 2 对我有用

选项 1 -(此后我遇到了不同的错误,但它部署了合约)

https://github.com/ethereum/solidity/issues/13159#issuecomment-1826481491

const overrides = {
    gasPrice: 2000000000, // Can set this >= to the number read from Ganache window
    gasLimit: 6721975, // Use the same gasLimit as read from Ganache window (or a bit higher if still having issue)
};
console.log("Deploying contract, please wait...");
const contract = await contractFactory.deploy(overrides);

选项 2(无需添加覆盖):

更改solc版本“solc”:“0.8.7-fixed”

更改合约编译指示中的编译器版本 ^0.8.7;

© www.soinside.com 2019 - 2024. All rights reserved.