Web3.js – Migrating Contracts With Specific Account Without Hardcoded Address Using Truffle and Ganache

migrationtruffletruffle-migrationweb3js

Block Builders! I am trying to migrate my two smart contracts using truffle and Genache. I would like to specify the deploying accounts existing locally. However, when I try to migrate the contracts I get error prompt that the provided address being invalid.

Here is my 2_deployed_contracts.js

var Bank = artifacts.require("Bank");
var Client = artifacts.require("Client");

module.exports = function(deployer, accounts) {
  deployer.deploy(Bank, {from: accounts[0], value: 
  web3.utils.toWei("30", "ether")}).then((bank)=>{
    return deployer.deploy(Client, bank.address, {from:accounts[1]});
  });
};

and the reported error prompt:

Error:  *** Deployment Failed ***

"Bank" -- Provided address "d" is invalid, the capitalization checksum test 
failed, or its an indrect IBAN address which can't be converted..

at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle- 
deployer/src/deployment.js:364:1
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)

Only when I hard code the account address at from field, the migration success. The accounts variable seems not working like most of the other posts suggested. I could not figure it out why, because I thought truffle would inject accounts variable.

Best Answer

You've got the accounts argument at the wrong position (2nd instead of 3rd).

Change this:

module.exports = function(deployer, accounts)

To this:

module.exports = function(deployer, network, accounts)

P.S.: In the Provided address "d" is invalid error, the d is probably the first letter in your network name - development - as configured in your Truffle configuration file (truffle-config.js).

Related Topic