Truffle-Migration

松露遷移:參數數量無效

  • September 15, 2022

松露遷移:參數數量無效

我有以下兩個智能合約(SC):

pragma solidity 0.5.16;

contract Phishable {
   address public owner;
   constructor () public{
       owner = msg.sender;
   }
   function () external payable {} 
   function withdrawAll(address payable _recipient) public payable {
       require(tx.origin == owner);
       _recipient.transfer(address(this).balance);
   }
}

== 另一個是:

pragma solidity ^0.5.16;
interface Phishable{  
  function withdrawAll(address payable _recipient ) external;
}
contract PhishableAtt {
   address public owner;
   uint public  count=0;
  
   constructor () public {
       owner = msg.sender;
   }
   function() external payable  { 
     count++; 
     if (count < 2 ) 
        Phishable(msg.sender).withdrawAll(address(msg.sender.balance));
     
  }
}

遷移文件是:

var victim   = artifacts.require("Phishable");
var attacker = artifacts.require("PhishableAtt");


module.exports = function(deployer, network, accounts){
  deployer.deploy(victim).then(function(){
  return deployer.deploy(attacker, victim.address);});
  
};

我收到以下錯誤:

部署“PhishableAtt”————————

錯誤:*** 部署失敗 ***

“PhishableAtt”——“未定義”的參數數量無效。得到 1 預期 0!。

at /home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at process._tickCallback (internal/process/next_tick.js:68:7) Truffle v5.1.67 (core: 5.1.67) Node v10.23.3

有人請指導我。

祖爾菲。

您正在嘗試傳遞 1 個參數來部署一個 contract 實例PhishableAttdeployer.deploy(attacker, victim.address);})但該PhishableAtt合約的建構子constructor () public需要 0 個參數。

正確的 2_deploy_contracts.js 是:

var Phishable   = artifacts.require("Phishable");
var PhishableAtt = artifacts.require("PhishableAtt");


module.exports = function(deployer, network, accounts){
  deployer.deploy(Phishable);
  deployer.deploy(PhishableAtt);
  
};

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