“迁移”在部署时遇到无效的操作码

Joe*_*son 4 javascript ethereum solidity truffle ganache

当我执行“松露部署”命令时,我突然开始收到“部署时迁移遇到无效操作码”错误。

\n

我的迁移文件没有更改,所以我不确定为什么突然收到此错误。每个发布相同错误的人都只是建议下载最新版本的 ganache/truffle,但我已将我的 truffle 和 ganache 更新到最新版本,但仍然收到错误。

\n

这是完整的错误:\n\xe2\xa0\x8b 从 solc-bin 获取 solc 版本列表。尝试 #1\n开始迁移...

\n
\n

网络名称:'development'\n网络 ID:5777\n区块 Gas 限制:6721975 (0x6691b7)

\n
\n

1_initial_migration.js

\n

\xe2\xa0\x99 从 solc-bin 获取 solc 版本列表。尝试#1\n部署“迁移”

\n

*** 从 solc-bin 部署***失败。尝试#1

\n

“迁移”在部署时遇到无效的操作码。尝试:

\n
    \n
  • 验证您的构造函数参数是否满足所有断言条件。
  • \n
  • 验证构造函数代码不会越界访问数组。
  • \n
  • 将原因字符串添加到断言语句中。
  • \n
\n

退出:通过在 Etherscan 上检查上面的交易哈希值来手动查看成功的交易。

\n

错误:*** 部署失败 ***

\n

“迁移”在部署时遇到无效的操作码。尝试:

\n
    \n
  • 验证您的构造函数参数是否满足所有断言条件。
  • \n
  • 验证构造函数代码不会越界访问数组。
  • \n
  • 将原因字符串添加到断言语句中。
  • \n
\n
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:330:1\n
Run Code Online (Sandbox Code Playgroud)\n

Truffle v5.9.2(核心:5.9.2)\nNode v18.7.0

\n

迁移.sol

\n
// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\ncontract Migrations {\n    address public owner;\n    uint256 public lastCompletedMigration;\n\n    constructor() {\n        owner = msg.sender;\n    }\n\n    modifier restricted() {\n        require(msg.sender == owner, "Restricted to contract owner");\n        _;\n    }\n\n    function setCompleted(uint256 completed) public restricted {\n        lastCompletedMigration = completed;\n    }\n\n    function upgrade(address new_address) public restricted {\n        Migrations upgraded = Migrations(new_address);\n        upgraded.setCompleted(lastCompletedMigration);\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

1_initial_migration.js

\n
const Migrations = artifacts.require("Migrations");\n\nmodule.exports = function(deployer) {\n    deployer.deploy(Migrations);\n};\n
Run Code Online (Sandbox Code Playgroud)\n

小智 9

尝试更改您的 pragma 和 solc 版本

迁移.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
Run Code Online (Sandbox Code Playgroud)

truffle-config.js

compilers: {
    solc: {
      version: "0.5.1"
}
Run Code Online (Sandbox Code Playgroud)

有时,solc 适用于 0.8.20 或 0.7.3