Visibility in solidity
Visibility in solidity
From where I can access an variable or a function is called visibility. kha se mai contract ke function or variable ko access kr skta hun vhi visibility hai
There are two places from there we can access a variable or function of a contract-
- Contract itself
- Contract that inherits it contract
- Outside of the contract
There are four types of visibility in solidity-
- public
- private
- internal
- external
public - public visibility can access both contract itself and contract that inherits it. It will cost more gas as it can be access from both.
private - private visibility can access only by contract itself.
internal - internal visibility is like private but it also can be access by contract that inherits it.
external - external visibility can only access outside of the contract means it can access by EOA (Externally Owned Account) like Metamask and other wallet.
Let's understand with given example below-