This is my doctor contract.

pragma solidity ^0.4.24;

contract doctor {

    struct doctor_ds {
        address doctor_address;
        string speciality;
    mapping(address => doctor_ds) public doctors_list;
    address hospital_address;

    function doctor() {
        hospital_address = msg.sender;

    function add_doctors(address _new_doctor_address, string _speciality) {

        doctors_list[_new_doctor_address].doctor_address = _new_doctor_address;
        doctors_list[_new_doctor_address].speciality = _speciality;

    function doctor_exist(address _doctor) public view returns(bool) {
        if (doctors_list[_doctor].doctor_address == _doctor) {
            return true;
        } else {
            return false;


This my patient contract.

pragma solidity ^0.4.24;

import "./doctor.sol";

contract patient {

    doctor doctor_obj;

    function patient(address _doctor_contract) {
        doctor_obj = doctor(_doctor_contract);

    function check_if_doctor(address _ddoctor) returns(bool) {

        return doctor_obj.doctor_exist(_ddoctor);

    function add_doc(address _d, string _s) {
        doctor_obj.add_doctors(_d, _s);

    function A() payable {


I am getting gas exceeded error, when i am calling doctor exists in patient contract(using remix and private ethereum blockchain) and also i want to create front end for patient contract, But How doctor contact's ABI will used in calling patient contract's add_doc and check_if_doctor functions. I don't know code for web3js when contracts interact with each other. Somebody please help

1 Answer 1


I've tried to compile it after changing the patient constructor to:

doctor_obj = new doctor();

This way it will automatically create a new doctor contract when a patient is deployed. After that "add_doc" and "check_if_doctor" works just fine.

So, deploy the patient, the result abi will include both contracts functions because patient depends on doctor. I think you'll be able to use the same abi to interact directly with the two contracts. But the contract addresses will be different.

  • I have used interface in solidity and it works fine. Thanks siid for reply. Jun 4, 2018 at 10:38

Your Answer

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

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