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

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:

  • 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 – Arash Kiani Aug 17 '18 at 7:41
  • Consider rephrasing the question. It's unclear if you are focused on deployment or testing. – Rob Hitchens - B9lab Aug 17 '18 at 14:57
  • Done, hope it helps others ) – Arash Kiani Aug 18 '18 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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