4

enter image description hereI have two contracts "college" and "department" . They are dependent contract. How do I deploy them in Ethereum Wallet ?

Sample Code :

contract Department {
    function enroll(uint depID, address student) returns (bool ret) {
           return true;
      }
}

contract College {
    address student;
    Department dept_instance;

    function College ( address _student , address _department  ) {
        student = _student;
        dept_instance = _department;
     }

    function chooseDept ( uint id ) payable returns (bool value) {
        bool ret = student.send(msg.value);
        if (!ret)
            return dept_instance.enroll(id, msg.sender);
        else
            throw;
    }
}

enter image description here

4

By "wallet" I assume you mean Mist.

When a source file has two contracts, as above, Mist will let you choose which contract you want to deploy. In this case, deploy the Department first.

Find the deployed department contract and copy its address to the clip board. It's not obvious, but with some persistence you can get the full address on the screen and copy it.

Then, return to "contracts" to deploy College.

Since College's constructor requires address _department, Mist is going to offer a field where you can specify the data. Paste, so Department's address gets passed into the constructor.

In line 13, use _department to create an instance of Department. Like this: dept_instance = Department(_department);

contract Department {

    function enroll(uint depID, address student) returns (bool ret) {
           return true;
    }
}

contract College {
    address student;
    Department dept_instance;

    function College ( address _student , address _department  ) {
        student = _student;
        dept_instance = Department(_department);
     }

    function chooseDept ( uint id ) payable returns (bool value) {
        bool ret = student.send(msg.value);
        if (!ret)
            return dept_instance.enroll(id, msg.sender);
        else
            throw;
    }
}

Hope it helps.

  • I tried the same . However when deploying "College" contract - Mist compiler indicates about missing Department Identifier not found or not unique. Department dept_instance; ^--------^ – sun Feb 22 '17 at 4:27
  • I didn't realize there was an oversight in the code. Updated my answer with a little correction in line that was causing the compiler to complain. – Rob Hitchens - B9lab Feb 22 '17 at 15:17
  • no problem Rob . Thank you for rightly pointing out. I am able to deploy the contract. However when calling "chooseDept(): function, I am facing another error. Sorry if this is a basic question. I am attaching the current problem screenshot for your reference – sun Feb 22 '17 at 19:09
  • 1
    Just doing my human parsing here. You've got a throw in that function, so it's your most likely reason. Working backwards, if student.send() fails, it will throw. Backwards from there, it looks like student was set by the constructor. Was it? Suggest "address public student;" so you can see it for troubleshooting purposes. – Rob Hitchens - B9lab Feb 22 '17 at 19:19

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.