5

UPDATED BELOW: (What worked for Me)

While compiling and running the following code on Remix. When I try to initialize Master with _ownerName, I get the following error "This contract does not implement all functions and thus cannot be created".

I wanted to create new Customer Contracts using the CustomerTemplate Contract

pragma solidity ^0.4.11;


//------------------------------------------------------------------------------------ 
//----- Templates 
//----- 
//------------------------------------------------------------------------------------ 

contract CustomerTemplate {

    bytes32 public customerName;
    bytes32 public customerLoc;

    function CustomerTemplate (bytes32 _customerName, bytes32 _customerLoc)  {

        customerName    = _customerName;
        customerLoc     = _customerLoc;

    }

}

//------------------------------------------------------------------------------------ 
//----- Master 
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------ 

contract Master is CustomerTemplate{

    address public owner;
    bytes32 public ownerName;
    address[] newCustomers;

    modifier onlyByMaster()  {
        require(msg.sender == owner);
        _;
    }

    function Master (bytes32 _ownerName) {

        owner = msg.sender;
        ownerName = _ownerName;
    }

    function createCustomer (bytes32 _customerName, bytes32 _customerLoc) {

        address myCustomer = new CustomerTemplate(_customerName, _customerLoc);
        newCustomers.push(myCustomer);
    }

    function killContract() constant onlyByMaster {

        if (msg.sender == owner) selfdestruct(owner);

    }

}

(UPDATE) The following worked for me:

pragma solidity ^0.4.15;


contract Template {

    bytes32  public custName;
    bytes32  public custLoc;
    address  public contractAddress;

    function Template () {

        custName            = "0xDEFAULT";
        custLoc             = "0xDEFAULT";
        contractAddress     = address(this);

    }

    function AssignCustomerAttributes (bytes32 _custName, bytes32 _custLoc)  
        returns (bool isSuccess) {

        custName    = _custName;
        custLoc     = _custLoc;

        contractAddress  = address(this);

        return true;

    }

}

//------------------------------------------------------------------------------------ 
//----- Master 
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------ 


pragma solidity ^0.4.15;


contract Template {

    bytes32  public custName;
    bytes32  public custLoc;
    address  public contractAddress;

    function Template () {

        custName            = "0xDEFAULT";
        custLoc             = "0xDEFAULT";
        contractAddress     = address(this);

    }

    function AssignCustomerAttributes (bytes32 _custName, bytes32 _custLoc)  
        returns (bool isSuccess) {

        custName    = _custName;
        custLoc     = _custLoc;

        contractAddress  = address(this);

        return true;

    }

}

//------------------------------------------------------------------------------------ 
//----- Master 
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------ 

contract Master {

    address  public     masterContractAddress;
    bytes32  public     masterName = "";
    Template    myCustTemp; 

    function Master () {

        masterContractAddress = address(this);

    }

    function updateOwnerName (bytes32 _masterName)  {

        masterName = _masterName;

    }

    function createCustomer (bytes32 _custName, bytes32 _custLoc)  returns (bool flag) {

        Template myCust = new Template();

        if (myCust.AssignCustomerAttributes(_custName, _custLoc)) {

            return true;

        } else return false;

    }


}
  • I think master constructor need to provide all the arguments needed to the parent class. – Achala Dissanayake Sep 25 '17 at 18:08
  • Hi @AchalaDissanayake, Thanks for your input. I have yet to try it out. I am trying to fix another issue before I test this out and provide my feedback. ethereum.stackexchange.com/questions/27167/… – userDSSR Sep 26 '17 at 14:53
  • cool, good luck with your stuff :) – Achala Dissanayake Sep 26 '17 at 14:59
  • @AchalaDissanayake, I provided the updated code that worked for me. Thanks, – userDSSR Sep 26 '17 at 17:22
  • 1
    great that you got it working, but I see no inheritance there. the error of the original code you posted was due to missing arguments while inheritance is used :) – Achala Dissanayake Sep 26 '17 at 17:27
3

You need to provide all the arguments needed for the parent class. From the solidity docs here,

Derived contracts need to provide all arguments needed for the base constructors.

So the master constructor would look like,

function Master (bytes32 _ownerName, bytes32 _loc) CustomerTemplate(_ownerName, _loc) {

    owner = msg.sender;
    ownerName = _ownerName;
}
  • What if the inherited contract doesn't have any constructor args? Doing CustomerTemplate() still throws "This contract does not implement all functions" – JohnAllen Oct 10 '17 at 22:12
2

I had the same issue. It might happen if you use inheritance.

The fix is fairly trivial. There is a drop-down near the "Create" button in Remix (aka Browser-Solidity). You just need to select the actual contract implementation to deploy, not the interface.

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.