1

I checked this but it does not help me. I am writing an inherited contract and I would like to hide the CheckValue function from the console. How do I go about this? I wish to check if the value I am entering in the withdrawal section is being verified on its own.

This is working, I just wish to hide the function from the console. Changing visibility throws an error and I only wish to hide CheckSum instead of the others.

Code below, I'm new to solidity :)

pragma solidity ^0.4.25;

interface Regulator{
        function CheckValue(uint amount) external returns(bool);

    function loan() external returns(bool);
}
contract PracticeInheritance is Regulator{
    uint private value;

    constructor (uint amount) public{
        value +=amount;
    }
    function deposit(uint amount) public{
        value += amount;
    }
    function withdraw(uint amount) public{
        if (CheckValue(amount)){
            value -= amount;
        }

    }

    function balance() view public returns(uint){
        return value;
    }

     function CheckValue(uint amount)public returns(bool){
            return amount <= value;
        }
        function loan()public returns(bool){
            return value >=0;
        }
}


contract PracticeContract is PracticeInheritance(500){
    string private name;
    uint private age;

    function setName(string _name) public{
        name = _name;
    }

    function setAge(uint _age) public{
        age = _age;
    }
    function getName() public constant returns(string){
        return name;}

        function getAge() public constant returns(uint){
        return age;}


}

I wish to hide it from here but the functionality must remain same i.e it should still check the value passed from withdraw but CheckValue should not show in the console here enter image description here

  • What do you mean by " I just wish to hide the function from the console."? – Henk Sep 18 '18 at 7:06
  • Ah one sec. Let me just give you a screenshot – R.D Sep 18 '18 at 7:07
  • Done @Henk, this is what I meant – R.D Sep 18 '18 at 7:09
1

You can't make public inherited methods private. That would break the inheritance system. You could restrict access to it, however, like in the answer you referred to.

To hide the function to Remix, you could create a new interface, which contains all methods you do want to show, and does not contain CheckValue.

It would look something like this:

interface PracticeContractFacade {
    function setName(string _name) public;
    function setAge(uint _age) public;
    function getName() public view returns(string);
    function getAge() public view returns(uint);
    function loan() external returns(bool);
    function deposit(uint amount) public;
    function withdraw(uint amount) public;
    function balance() view public returns(uint);
}

Then follow these steps:

  1. Deploy PracticeContract
  2. Copy the PracticeContract's address
  3. Use the deployed PracticeContract's address to instantiate the new interface (PracticeContractFacade). You can use the At Address button for that, pasting the copied address into the textbox next to it.
  4. The newly instantiated PracticeContractFacade is now showing in the 'Deployed Contracts' section. It does not contain a button for the CheckValue function. (Yay!)
  5. Optional: Click on the x of the PracticeContract controls in the 'Deployed Contracts'.

To hide it for web3, you should just remove the function declaration from the ABI specification. Or you could use the interface method as well.

  • But wouldn't this approach just make it redundant or cost more gas on execution? – R.D Sep 18 '18 at 7:20
  • No, because your're not actually deploying the PracticeContractFacade. You're just telling Remix how it can act on a contract that's deployed at a certain address. That contract actually being a PracticeContract doesn't matter – Henk Sep 18 '18 at 7:22
  • I'm not using web3 right now. Just doing it on remix. I tried your method but it isn't working. Even after instantiating with the At Address and deploying again, the checkvalue part is still showing – R.D Sep 18 '18 at 8:01
  • I clarified the steps. – Henk Sep 18 '18 at 8:07
  • 1
    Ah nvm I managed to make it work. I had to select the option that was above the deploy button. Thanks! – R.D Sep 18 '18 at 8: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.