我正在尝试在 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 正在部署,请稍候...
有人可以告诉我发生了什么事吗?
尝试这些,选项 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;