Solidity

“遷移”在使用 Truffle 部署 Migrations.sol 時遇到了無效的操作碼

  • April 14, 2021

truffle migrate 嘗試部署 Migrations.sol 合約時發生錯誤,我不明白為什麼

pragma solidity >=0.4.21 <0.6.0;

contract Migrations {
 address public owner;
 uint public last_completed_migration;

 constructor() public {
   owner = msg.sender;
 }

 modifier restricted() {
   if (msg.sender == owner) _;
 }

 function setCompleted(uint completed) public restricted {
   last_completed_migration = completed;
 }

 function upgrade(address new_address) public restricted {
   Migrations upgraded = Migrations(new_address);
   upgraded.setCompleted(last_completed_migration);
 }
}

遷移.sol

1_initial_migration.js
======================

  Deploying 'Migrations'
  ----------------------
Error: Error: Error:  *** Deployment Failed ***

"Migrations" hit an invalid opcode while deploying. Try:
  * Verifying that your constructor params satisfy all assert conditions.
  * Verifying your constructor code doesn't access an array out of bounds.
  * Adding reason strings to your assert statements.

   at Object.run (C:\Users\Sim'S\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:92:1)
   at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.21 (core: 5.0.21)
Node v10.15.3

錯誤資訊

剛剛遇到同樣的錯誤。在這種情況下,我執行的是舊版本的 ganache-cli 並且必須更新 ganache,所以幫助執行

npm install -g ganache-cli

就我而言。

經過大量研究後,我發現更新 truffle 版本可以解決這個問題。

npm install -g 松露

引用自:https://ethereum.stackexchange.com/questions/72036