Visiblity Specifiers
Visibility specifiers are analogous to the access specifiers or modifiers in object oriented languages, they define the visibility and accessibility of the function or variables.
- public variables and functions are accessible from everywhere.
- external functions are only callable from external world outside the contract.
- internal functions and variables are accessible in current and inherited contracts.
- private variables and functions are accessible only in the current contract.
Example:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.25;
contract GeekContract {
function externalFunction() external {
// can only be called from the outside
}
function internalFunction() internal {
// Only accessible in this contract and child contracts
}
function privateFunction() private {
// Accessible only in this contract
}
function publicFunction() public {
// Accessible Everywhere!
}
}
Output:
Explanation:
As you can see, only the public and the external functions are visible in the output. Because private & internal functions are accessible on the contract, and the sub-contracts respectively.
Unlock the Power of Solidity: Exploring the Essential Keywords for Smart Contract Development
Solidity is a smart contract programming language built solely to develop smart contracts that can be deployed on blockchains. C++ and JavaScript inspired it, an Object Oriented and High-Level language (HLL), that helps developers define the behaviour and rules for a Decentralized Application (Dapp). Smart contract facilitates autonomous, secure, and efficient transaction execution on the blockchain without needing any intermediary (self-executable) and solidity provides the base framework for achieving the same.
It is essential to understand the common keywords used in solidity to solidify your core understanding of the language so in this article, we’ll pin down some prominent keywords that help us develop these smart contracts by embracing the true power of solidity language.
Table of Content
- Contract
- Constructor
- Data Types
- Delete
- Enum
- Function
- Interface
- Import
- Struct
- Visiblity Specifiers
- Exception Handling
- Pragma Directive
- License Defintion
- Modifier
- Data Location
- Global Variables
- Fallback Function
- SelfDestruct
- ‘assembly’ and ‘inline assembly’