1

I have two Contracts - a contract with a single constructor argument (ContractB), and a launcher that deploys new instances (Launcher).

Using Truffle for testing how can I link the contracts without deploying contract B, given that contract B will return an error if deployed without prams

Error: ContractB contract constructor expected 1 arguments, received 0

Here is the link to Git repository

deploy_contracts.js

var Launcher = artifacts.require("./Launcher.sol");
var ContractB = artifacts.require("./ContractB.sol");

module.exports = function(deployer) {
  deployer.deploy(ContractB);
  deployer.link(ContractB, Launcher);
  deployer.deploy(Launcher);
};

Test File

var Launcher = artifacts.require("./Launcher.sol");

contract('Launcher', function(accounts) {
  it("Launcher Deploy", function() {
    return Launcher.deployed().then(function(instance) {
      console.log(instance)
    })
  });
});

Launcher.sol

pragma solidity ^0.4.18;

import "./ContractB.sol";

contract launcher {

    function launch() public returns(address) {
        ContractB contractLocation = new ContractB(msg.sender);
        return(contractLocation);
    }
}

ContractB.sol

pragma solidity ^0.4.18;

contract ContractB {
    address public owner;
    constructor(address addr) public {
    owner = addr;
  }

    function get() public view returns(address) {
        return(owner);
    }
}

Here is the link to Git repository

1 Answer 1

2

You don't deploy ContractB with migrations.

You should use a migration to deploy Launcher. There is no need to deploy ContractB because that's Launcher's job.

Couple of things to watch out for:

3
  • Hi Rob, Thank you for your answer but I was hoping we could keep the answer focused on truffle deployment rather than solidity code improvement Aug 17, 2018 at 7:41
  • Consider rephrasing the question. It's unclear if you are focused on deployment or testing. Aug 17, 2018 at 14:57
  • Done, hope it helps others ) Aug 18, 2018 at 10:16

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.