Truffle Assignment

Hi, I’m getting an error when trying to migrate the Wallet contract (https://github.com/aelkins3/helloworld.git). Please take a look at my code and help me understand the problem. Thank you. I hope that providing this link is a good way to solicit help from you all. Thanks.

This is the error:

   Deploying 'Wallet'
   ------------------
 *** Deployment Failed ***

"Wallet" -- Invalid number of parameters for "undefined". Got 0 expected 2!.


Exiting: Review successful transactions manually by checking the transaction hashes above on Etherscan.


Error:  *** Deployment Failed ***

"Wallet" -- Invalid number of parameters for "undefined". Got 0 expected 2!.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:379:1
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:68:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:152:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:117:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:94:1)
    at module.exports (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/runMigrations.js:10:1)
    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:41:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)

The link returns 404 error.

It seems you are not inputting data to 2 fields somewhere in the code, where your code requires to feed two sets of data instead of none. Make sure to check constructor or function parameters in your code and make sure you are inputting two parameters when it is required.

2 Likes

yes @Gry is correct its likley parameters your not defining in the constructor. please update your repo or if its private make it public so we can check to confirm for u

2 Likes

Thanks for the replies. I just changed my repo to public here: https://github.com/aelkins3/helloworld.git. Thanks for the feedback, I will review it now.

Okay @Gry @mcgrane5. This constructor function that needs two inputs is located in my Wallet.sol contract file I assume. I will try to track this down while you all kindly confirm from my GitHub link if you have time.

@Gry @mcgrane5

So I simply executed the “migrate” command in the Truffle develop console environment… I see that there is a constructor in my Wallet contract, but why would this cause an error when trying to deploy with the migration? I’ll try to do some more research or review on this. Thanks.

2 Likes

“Truffle Migrate” deploys the contract (to a blockchain for example). When your using Remix or Visual Studio Code, you need to input constructor parameters when your deploying the contract. On Remix you can just type parameters in the UI, but on Visual Studio you need to put the constructor params in to the migration file.

constructor(address[] memory _owners, uint _limit) {

        owners = _owners;

        limit = _limit;

You have a constructor in your smart contract which takes number of owners and number of limit for approvals as data that is inputted when deployed. If this info is not inputted, the migration most likely leads to errors.

2 Likes

@Gry yeah i think hes using vs code so the error is coming from his wallet migration file is where the error is coming from. so @limitlessandrew set up your params for the constructot in your migation file you need to do something like this. so you have two arguments you need to define in your constructor, namely

 constructor(address[] memory _owners, uint _limit) {
        owners = _owners;
        limit = _limit;
    }

to define them you need to do so in your migration file for your wallet contract. the problem is that your current migration file is not passing the values for owners array and limit into your contracts constructor on creation hence the error. so this is your original current file

const Wallet = artifacts.require("Wallet");

module.exports = function (deployer) {
  deployer.deploy(Wallet);
};

you need to change it to something akin to the following by passing it an owners array and value for the limit. so change your wallet migratiojs to something like

const Wallet = artifacts.require("Wallet");

//network is optional here but i usually add it anyways
//we need accounts so we can set up your owners
//array
module.exports = (deployer, network, accounts) => {
  const owners = [accounts[0], accounts[1], accounts[2]]
  const limit = 2
  
  //now that we have defined the nessecary params for the
 //contracts constructor you will be able to deploy
  // you just simply add the values in here in the same order
  // that you define them in your actual contract
  deployer.deploy(owners, limit)
}
2 Likes

Okay @Gry @mcgrane5. This all makes sense, but here is the output with the updated code.

1 Like

ok it seems to not like the fact that your passing in the array. try this instead.
wallet.sol

constructor(address owners1, address owners2, address owners3, uint _limit) {
        owners.push(owners1);
        owners.push(owners2);
        owners.push(owners3);
        limit = _limit;
    }

then in truffle migratons file
wallet migrations.js

module.exports = (deployer, network, accounts) => {
  const owners1 = accounts[0]
  const owners2 = accounts[1]
  const owners3 = accounts[2]
  const limit = 2
  deployer.deploy(owners1, owners2, owners3, limit)
}

@thecil No luck again. It didn’t seem like it would be this complicated to migrate this file in the training video.

1 Like

ahhh i see what the problem is i think. accounts is in the wrong position. please put back in the network option as passing accounts in as the second param its not getting read as accounts but rather in the place of the network sorry this my bad as i said t was optional above. and also one thing i see is aswell you not actually passing the contract you want to deply into the deployer function. this is what we imported the Wallet for. but that was my typo not yours. sorry its easy to make mistakes when trynna come up with code directly in forum message

so change your contract back to the way it was wher eyou are passing in the array of addresses and then use this as your migrations file

const Wallet = artifacts.require("Wallet");

//network is optional here but i usually add it anyways
//we need accounts so we can set up your owners
//array
module.exports = (deployer, network, accounts) => {
  const _owners = [accounts[0], accounts[1], accounts[2]]
  const _limit = 2
  
  deployer.deploy(Wallet, _owners, _limit)
}
5 Likes

That did it. Good work, thank you for the help. Do you work for Moralis?

1 Like

yes here at the academy

1 Like