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?

2 Answers 2


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.

  • 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, 2021 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, 2021 at 5:47


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).

  • 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, 2021 at 5:21
  • It can't be overridden afterwards, but before deployment yes. Aug 27, 2021 at 5:49

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.