Solidity
部署合約時出現松露錯誤
有誰知道如何解決這個問題?我已經嘗試編譯和部署我的合約來獲取地址,為什麼會出現這個錯誤
錯誤:
1_initial_migration.js ====================== Deploying 'towater' ------------------------- Error: Error: Error: *** Deployment Failed *** "towater" -- Invalid number of parameters for "undefined". Got 0 expected 2!. at Object.run (/usr/local/lib/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.24 (core: 5.0.24) Node v10.16.0
1_initial_migrations.js
文件:var towater = artifacts.require("towater"); module.exports = function(deployer) { deployer.deploy(towater); };
要解決錯誤,您需要在
migration
文件中傳遞建構子的參數。根據您的兩個參數:
// Untested // Deploy a single contract with constructor arguments deployer.deploy(towater, ["string_1", "string_2"], ["0x15458ef540ade6068dfe2f44e8fa733c", "0x15458ef540ade6068dfe2f44e8fa734c"] );
檢查松露文件。
使用 Truffle v5.0.39 時,上述語法無效。如果合約的建構子有參數,那麼 deploy 函式必須提供如下參數:
deployer.deploy( myContract, arg1, arg2, ...);
因此,例如,如果您的建構子採用兩個地址:
deployer.deploy(towater, "0x15458ef540ade6068dfe2f44e8fa733c", "0x15458ef540ade6068dfe2f44e8fa734c");