Truffle
Truffle migrate - TypeError: migrations.setCompleted 不是函式
我跑向
$ npx truffle migrate
Ganache 部署 2 個合約,但出現錯誤:This version of µWS is not compatible with your Node.js build: Error: Cannot find module './uws_darwin_x64_88.node' Falling back to a NodeJS implementation; performance may be degraded. Compiling your contracts... =========================== > Everything is up to date, there is nothing to compile. Starting migrations... ====================== > Network name: 'development' > Network id: 5777 > Block gas limit: 6721975 (0x6691b7) 1_initial_migration.js ====================== Deploying 'Migrations' ---------------------- > transaction hash: 0x4aace13bc13ed0956004c7bf4af40a052797d620d69bb95d412bec36271366e9 > Blocks: 0 Seconds: 0 > contract address: 0x76167b6D1E41AFEb8F55c36316D1DB0C1BD6BCba > block number: 1 > block timestamp: 1665666248 > account: 0xD7D15925b6b7760e27edA967700D2df22CaEad55 > balance: 99.99865868 > gas used: 67066 (0x105fa) > gas price: 20 gwei > value sent: 0 ETH > total cost: 0.00134132 ETH Exiting: Review successful transactions manually by checking the transaction hashes above on Etherscan. **TypeError: migrations.setCompleted is not a function** at Migration._deploy (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:98:1) at processTicksAndRejections (node:internal/process/task_queues:94:5) at Migration._load (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1) at Migration.run (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1) at Object.runMigrations (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:142:1) at Object.runFrom (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:107:1) at Object.run (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:91:1) at module.exports (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/runMigrations.js:10:1) at Object.module.exports [as run] (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:41:1) at runCommand (/Users/AAHD/.npm-global/lib/node_modules/truffle/build/webpack:/packages/core/lib/command-utils.js:201:1) Truffle v5.6.0 (core: 5.6.0) Node v15.14.0
這是 1_initial_migration.js 中的程式碼
const Migrations = artifacts.require("Migrations"); module.exports = function(deployer) { deployer.deploy(Migrations); };
我正在學習,這是我第一次部署,所以我不確定如何修復錯誤。謝謝您的幫助!
在contracts目錄中,你應該有
Migrations.sol
,它的程式碼應該是這樣的:// SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.9.0; contract Migrations { address public owner = msg.sender; uint public last_completed_migration; modifier restricted() { require( msg.sender == owner, "This function is restricted to the contract's owner" ); _; } // this might not be set correctly function setCompleted(uint completed) public restricted { last_completed_migration = completed; } }