0

In my 2_deploy_contracts.js file, I can successfully migrate all my contracts using the command truffle migrate. My problem is that after migration, I want to call a function from contract D and pass it the address of contract E.

My 2_deploy_contracts.js file looks like this (contract names replaced):

const A = artifacts.require("A");
const B = artifacts.require("B");
const C = artifacts.require("C");
const D = artifacts.require("D");
const E = artifacts.require("E");

module.exports = function(deployer) {
  deployer.deploy(A);
  deployer.deploy(B);
  deployer.deploy(C);
  deployer.deploy(D)
    .then(function() {
      return deployer.deploy(E, D.address);
    })
    .then(function() {
      return D.methods.setEContractAddress(E.address); // This line
    });
};

I have looked at other similar questions on this site but none have helped so far. How do I call the setEContractAddress() function from contract D after contract E is migrated?

Thank you for your help and time!

1 Answer 1

1

try this:

const D = artifacts.require("D");
const E = artifacts.require("E");

module.exports = async (deployer) => {
  await deployer.deploy(D)  
  const d = await D.deployed();    
  await deployer.deploy(E, d.address);
  const e = await E.deployed();
  await d.setEContractAddress(e.address);
};
1
  • Thanks for your help Javier, it works now! You only need to add an arrow to the code for it to compile properly, like this: async (deployer) => { :)
    – Wolfizzy
    Jun 16, 2022 at 14:10

Your Answer

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

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