Solidity
松露部署錯誤:“未定義”的參數數量無效。得到 1 預期 0!
我正在嘗試部署我的智能合約。當我執行 truffle compile 時,一切正常,但是當我執行 truffle migrate 時,我收到此錯誤消息:
錯誤:* 部署失敗 *
“KJToken”——“未定義”的參數數量無效。得到 1 預期 0!。
我試圖刪除我的建構文件夾並重置我的編譯,但沒有任何效果。即使我嘗試重置松露遷移,也會出現相同的錯誤。
這是我的部署contracts.js 程式碼:
var KJToken = artifacts.require('./KJToken.sol') module.exports = function (deployer) { deployer.deploy(KJToken).then(function () { return deployer.deploy(KJToken, KJToken.address) }) }
這是我的 kjtoken.sol
pragma solidity >=0.4.21 <0.7.0; contract KJToken { string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; //balances for each account mapping(address => uint256) balances; address devAddress; //Events; event Approval(address indexed _owner, address indexed _spender, uint256 _value); event Transfer(address indexed from, address indexed, uint256 value); // owner of account approves the transfer of an amount to another account mapping(address => mapping (address => uint256)) allowed; // contructor is automattically going to run when the smart contract is uploaded constructor() public { name = "KJtoken"; symbol = "KJ"; decimals = 18; devAddress = 0x22391dc3a3cD8e9774F426e5405C3440559D0a1e; uint initialBalance = 1000000000000000000*1000000; // 1M tokens balances[devAddress] = initialBalance; totalSupply += initialBalance; //set the total supply } function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } //Transfer the balance from owner's account to another account function transfer(address _to, uint256 _amount) public returns (bool success) { if (balances[msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) { balances[msg.sender] = _amount; balances[_to] += _amount; emit Transfer(msg.sender, _to, _amount); return true; } else { return false; } } function transferFrom( address _from, address _to, uint256 _amount ) public returns (bool success) { if (balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) { balances[_from] -= _amount; allowed[_from][msg.sender] -= _amount; balances[_to] += _amount; return true; } else { return false; } } // allow _spender to to withdraw from your account, multiple times, up to the _value amount. // if this functin is called again it overwrites the current allowance with _value. function approve(address _spender, uint256 _amount) public returns (bool success) { allowed[msg.sender][_spender] = _amount; emit Approval(msg.sender, _spender, _amount); return true; } }
您正在傳遞 1 個參數以嘗試部署一個 contract 實例
KJToken
:deployer.deploy(KJToken, KJToken.address)
但是這個合約的建構子需要 0 個參數:
constructor() public ...
這是因為您的建構子不接受任何參數。
將你的contract.js文件更改為:
var KJToken = artifacts.require("KJToken.sol"); module.exports = function (deployer) { deployer.deploy(KJToken); };