1

I have a contract that looks like this

pragma solidity >=0.7.0 <0.9.0;

contract SomeContract {

    uint256 public id;
    address public creator;

    enum Status {ACTIVE, INACTIVE}

    Status contractStatus;

    modifier checkStatus {

        require(contractStatus == Status.ACTIVE);

        _;

    }

    modifier onlyCreator {
    
        require(msg.sender == creator);

        _;

    }

    constructor() {

        contractStatus = Status.ACTIVE;
        creator = msg.sender;

    }

    function doSomething() external checkStatus {

        // do something here

    }

    function changeStatus(bool _isActive) external onlyCreator {

        if (_isActive) {
            contractStatus = Status.ACTIVE;
        } else {
            contractStatus = Status.INACTIVE;
        }
        
    }}

}

This contract works fine. The problem is after I deactivate the contract, people still can access public state variables like id and creator because solidity automatically creates a getter for each of these variables. Is there any faster way besides making it internal and creating my own getter and adding a modifier to it?

0

By default public variables have already built-in getter, you can stop that by changing the variable type to private or internal. But don't get confused with the word "private", because nothing is really private on the blockchain. Even if you change id and creator to private type this will remove the automatic getters that you see in Remix, but this data is not hidden and everyone can still access it.

On top of my head the first ideas I have to save sensitive data in smart contracts are via asymmetric encryption ( the contract is saving encrypted format of the data and the data is being decrypted on the front end ) or keep the sensitive data offchain and make connection to it with the smart contract.

2
  • The data is not that private. I just want to show that the contract is inactive and better not trying to access it. So, I guess I just have to change the variable type and create a getter myself? Aug 27 at 5:23
  • Yes, then this new getter should have modifier attached to it with restriction which is saying which address is allowed to call this getter. Aug 27 at 5:47
0

No.

The creation of the public getter is automatic and you can't influence that.

I think you can override the getter in an inheriting function, but that certainly isn't easier than writing it in the same function.

And in any sense, there is no way to "hide" information in a contract. Even if users can't access it directly, knowledgeable users will be able to get the data (for example getting it from the block before the data was restricted).

2
  • Ah, I never thought of that because the node is secure in a private network and the client can not access the node directly or even use rpc (there is a filter which IP can access it). So, public state variable getter can be overridden? Aug 27 at 5:21
  • It can't be overridden afterwards, but before deployment yes. Aug 27 at 5:49

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.