Restricting Access Pattern

Learn about the restricting access pattern in Solidity.

Access restrictions are a way to control who can interact with a smart contract and how they can interact with it. They’re important for security, modularity, and privacy. In Solidity, access restrictions are a critical contract design pattern. They specify who can read a contract’s state, update its state, or invoke its capabilities. While it’s critical to recognize that transaction data and current contract status are available and accessible to anybody on the blockchain, access limits allow us to regulate and limit interactions with contracts.

Managing read access

By establishing the visibility of state variables in Solidity, we can regulate who can read the state of our contract. State variables are set to internal visibility by default, which means they can only be accessible within the contract and any related contracts. When we declare state variables public—meaning they’re accessible to anyone—including other contracts and third-party companies.

To limit read access:

  • Default visibility: To restrict access to contract internals, we ...