0

Truffle migrate: Invalid number of parameters

I have got following two smart contracts (SCs):

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);
    }
}

== and the other one is:

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));
      
   }
}

and the migration file is:

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);});
   
};

I am getting following error:

Deploying 'PhishableAtt' ------------------------

Error: *** Deployment Failed ***

"PhishableAtt" -- Invalid number of parameters for "undefined". Got 1 expected 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

Somebody please guide me.

Zulfi.

2 Answers 2

1

You're attempting to pass 1 argument to deploy an instance of contract PhishableAtt, deployer.deploy(attacker, victim.address);}), but the constructor of the PhishableAtt contract constructor () public takes 0 arguments.

2
  • Please guide me the correct syntax of 2_deploy_contracts.js
    – zak100
    Sep 14, 2022 at 23:35
  • 1
    use deployer.deploy(attacker) instead of deployer.deploy(attacker, victim.address) Sep 14, 2022 at 23:42
0

The correct 2_deploy_contracts.js is:

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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.