无法通过ganache gui部署智能合约

问题描述 投票:0回答:1
const ethers = require("ethers");
const fs = require("fs-extra");

async function main() {
  try {
    const provider = new ethers.JsonRpcProvider("http://127.0.0.1:7545");
    const wallet = new ethers.Wallet(
      "0x3fff57a423422c9af7026a90b58be81e66bd80e7587edd7ec61060f6daaed287",
      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 hang on...");

    const contract = await contractFactory.deploy({
      gasLimit: 6721975,
      gasPrice: 20000000000,
    });

    console.log("Deployment Transaction:", contract.deployTransaction);

    console.log("Waiting for the contract to be mined...");
    await contract.deployTransaction.wait(1); // Wait for 1 block confirmation
    console.log("Contract deployed successfully!");

    // Call the `retrieve` function on the deployed contract
    console.log("Calling retrieve method...");
    const favNumber = await contract.retrieve();
    console.log("Favorite number:", favNumber.toString());
  } catch (error) {
    console.error("Error during deployment or function call:", error);
    process.exit(1);
  }
}

main();

现在,当我尝试部署``node deploy.js`时,这是弹出的终端错误 我的进步就在那里停止了,

rror during deployment or function call: Error: could not coalesce error (error={ "code": -32000, "data": { "hash": "0x71df1abf7ca0c92341bcbe285a19c83102635b35d9964bb5a1ba5da1b3456ddb", "message": "invalid opcode", "programCounter": 23, "reason": null, "result": "0x71df1abf7ca0c92341bcbe285a19c83102635b35d9964bb5a1ba5da1b3456ddb" }, "message": "VM Exception while processing transaction: invalid opcode", "name": "RuntimeError", "stack": "RuntimeError: VM Exception while processing transaction: invalid opcode\n    at EIP1559FeeMarketTransaction.fillFromResult (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:12745)\n    at Miner.<anonymous> (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:36703)
code=UNKNOWN_ERROR, version=6.13.4)
    at makeError (/Users/wasimchoudhary/ethersjs blockchain/ether-ssstorage/node_modules/ethers/lib.commonjs/utils/errors.js:129:21)
    at JsonRpcProvider.getRpcError (/Users/wasimchoudhary/ethersjs blockchain/ether-ssstorage/node_modules/ethers/lib.commonjs/providers/provider-jsonrpc.js:730:41)
    at /Users/wasimchoudhary/ethersjs blockchain/ether-ssstorage/node_modules/ethers/lib.commonjs/providers/provider-jsonrpc.js:302:45
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'UNKNOWN_ERROR',
  error: {
    message: 'VM Exception while processing transaction: invalid opcode',
    stack: 'RuntimeError: VM Exception while processing transaction: invalid opcode\n' +
      '    at EIP1559FeeMarketTransaction.fillFromResult (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:12745)\n' +
      '    at Miner.<anonymous> (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:36703)\n' +
      '    at async Miner.<anonymous> (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:35116)\n' +
      '    at async Miner.mine (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:39680)\n' +
      '    at async Blockchain.mine (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/dist/node/1.js:2:60063)\n' +
      '    at async Promise.all (index 0)\n' +
      '    at async TransactionPool.emit (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache/node_modules/emittery/index.js:303:3)',
    code: -32000,
    name: 'RuntimeError',
    data: {
      hash: '0x71df1abf7ca0c92341bcbe285a19c83102635b35d9964bb5a1ba5da1b3456ddb',
      programCounter: 23,
      result: '0x71df1abf7ca0c92341bcbe285a19c83102635b35d9964bb5a1ba5da1b3456ddb',
      reason: null,
      message: 'invalid opcode'
    }
  },
  payload: {
    method: 'eth_sendRawTransaction',
    params: [
 id: 9,
    jsonrpc: '2.0'
  },
  shortMessage: 'could not coalesce error'

从终端中删除了哈希值和二进制,这是长总结的错误

想要通过 ganache gui 本地环境进行部署,尝试了每个 npm 安装等和依赖项,因此我发现了我的丢失

dependencies solidity smartcontracts ethers.js ganache
1个回答
0
投票

你为什么用它?我发现您的部署脚本确实很简单,如果您是初学者,我不会推荐这样做。尝试一下 Apeworx、Hardhat 或 Foundry 之类的东西。

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