Solidity functions define how an Ethereum-compatible smart contract exposes operations and handles information. A function can be made callable from outside the contract, available only to related code, or restricted to the contract declaring it. Solidity uses four function visibility levels: public, external, internal and private. The separate view, pure and payable keywords describe permitted state access and value receipt, not who is authorized to call an operation. The Solidity 0.8.38 contract specification defines those rules.
The earlier EVM and smart-contract introduction, contract structure reference, and value-types and parameters lesson supply the prerequisites. The prior block-deadline exercise addressed chain timing; the present subject focuses on function interfaces and access boundaries rather than another timing scenario.
Elementary Overview
Think of a smart contract as a workshop with rooms and doors. A public function can be reached from outside the workshop and from other rooms inside. An external function is designed as a door for outside callers. An internal function stays within the workshop and its inherited extensions, while a private function is available only inside the original contract. A closed programming door does not make the activity secret: public blockchains preserve transaction records and contract storage that observers can inspect.
Learning Objectives
- Explain the four function visibility keywords and distinguish contract ABI entry points from internal calls.
- Explain why
privateis not encryption and why visibility is not caller authorization. - Distinguish
view,pureandpayable. - Read a small parent-and-child contract example and identify exposed functions.
- Use a local Remix VM to evaluate expected results without spending real cryptocurrency.
Terry White, “Solidity Tutorial: Function visibility (external, public, internal & private).” An identifiable educational video dedicated to the four visibility levels. Original video. The material predates Solidity 0.8.38; current language semantics are checked against the official compiler documentation.
Public and External Function Calls
A public function belongs to the externally callable contract interface and can also be called by name from inside the contract. In the sample, getNumber() and triple() are public. An external function also appears in the external contract interface, but it cannot be invoked by an ordinary unqualified internal call. Solidity treats a qualified external self-call as an actual message call with different gas and execution-context consequences. The official function visibility reference distinguishes those paths.
Neither keyword checks who the caller is. Unless additional conditions exist, any account or contract can call a public or external function. The educational setNumber method intentionally allows everyone to update a bounded number, so it must never be mistaken for a production access-control design. Restricting administrative operations requires explicit authorization rules such as a correctly implemented owner or role check, along with appropriate security review.
Internal and Private Functions
internal functions are callable from the declaring contract and compatible derived contracts. They do not appear as separately invocable methods in the external application binary interface, or ABI. The example’s _save() method is marked internal so its derived child can use it. private functions, including the example’s _double(), are callable only by code in the declaring contract, not by derived contracts. Leading underscores are naming conventions rather than access controls.
Function visibility regulates which Solidity code can directly call a function. It does not hide its implementation or stored data from blockchain observers. Solidity’s own documentation warns that private and internal restrict access from other contracts, not public visibility of data on chain. Never keep passwords, secret recovery phrases or private keys in state variables, regardless of declared visibility.
View, Pure, and Payable Are Separate Rules
view indicates that a function does not modify contract state. getNumber() reads a stored number, so view fits. pure disallows state reads as well as writes, which makes it suitable for triple(number) and the internal calculation _double(number). By contrast, payable permits a function to receive Ether with a call. A state-changing function without payable generally rejects attached Ether. Refer to the official 0.8.38 cheatsheet for each modifier’s meaning.
Calling a view function with an off-chain read ordinarily avoids a paid blockchain transaction, but submitting a transaction that executes a view function can still consume gas. The word view does not imply free network usage in every context. The sample deliberately omits payable operations, live-wallet connections and fund transfers to keep the exercise self-contained.
“Solidity Functions Tutorial | Visibility, Parameters & Return Values,” a separately identified educational overview of function declarations, return values, visibility, and view/pure/payable. Original YouTube page. Video identity is distinct from the earlier visibility-specific tutorial.
Executable Example for a Local Remix VM
The following code illustrates each visibility level, two state-read rules and inheritance. Save it as VisibilityLab.sol in Remix IDE. Select compiler 0.8.38, announced by the Solidity team on October 22, 2026. The pragma accepts any compatible 0.8 release from 0.8.20 upward. Use a Remix VM rather than Mainnet, a funded wallet or a live deployment:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract VisibilityLab {
uint256 private storedNumber;
function setNumber(uint256 number) external {
require(number <= 1000, "Number too large");
_save(number);
}
function getNumber() public view returns (uint256) {
return storedNumber;
}
function doubleStored() external view returns (uint256) {
return _double(storedNumber);
}
function _save(uint256 number) internal {
storedNumber = number;
}
function _double(uint256 number) private pure returns (uint256) {
return number * 2;
}
function triple(uint256 number) public pure returns (uint256) {
return number * 3;
}
function isZero() external view returns (bool) {
return getNumber() == 0;
}
}
contract VisibilityChild is VisibilityLab {
function saveFromChild(uint256 number) external {
require(number <= 1000, "Number too large");
_save(number);
}
}
Local Test Procedure and Expected Results
Compile the file, deploy VisibilityLab in the Remix VM and click getNumber(). The expected initial value is 0. Calling isZero() should return true, while triple(4) should return 12. Next, submit setNumber(7). After the simulated transaction, getNumber() should return 7, doubleStored() should return 14, and isZero() should return false.
Submitting setNumber(1001) is designed to revert with Number too large, leaving the previous stored value unchanged. Deploy the separate VisibilityChild contract and call saveFromChild(6); its inherited getNumber() should then report 6. Remix should offer buttons for public and external operations but not standalone buttons for _save() or _double(). The latter are not external ABI functions.
The expected outputs above are specifications for a reader-run lab, not results claimed from an executed EVM test. The publication environment has no Solidity compiler or Remix VM available, so contract compilation, EVM deployment and transaction assertions remain unverified. Arithmetic and declared access relationships were reviewed against the Solidity reference material; readers should reproduce the complete test sequence before relying on the example.
Security Boundaries and Common Errors
- Do not confuse
externalwith permission to call; it defines a call interface, not an allowlist. - Do not treat a
privatestate variable or function as confidential. Public chains expose storage and execution artifacts to observers. - Do not assume a derived contract can access private functions; only internal or public functions can be directly inherited for access in the demonstrated pattern.
- Do not describe
viewas inherently free of all gas costs; distinguish an off-chain call from a transaction. - Do not deploy an unrestricted setter protecting money or administrative state; the example is an educational laboratory.
Knowledge Check
- Which function kind can both outsiders and internal code normally call directly?
public. - Which kind is callable by a derived contract but absent from the external ABI?
internal. - Which keyword prevents reading contract state as well as modifying it?
pure. - Does a private variable hide a password on Ethereum? No; blockchain contents are publicly inspectable.
References
- Solidity 0.8.38: Function Visibility, official language behavior.
- Solidity 0.8.38: State Variable Visibility, getter and privacy limitations.
- Solidity 0.8.38: Modifiers, view, pure and payable definitions.
- Solidity Team: v0.8.38 Release Announcement, October 22, 2026.
- Official Remix IDE, browser-based Solidity experimentation.
Elementary Conclusion
Solidity uses visibility keywords to control which functions a contract exposes to other code. Public and external functions can be reached from outside, while internal and private functions are intended for specific parts of the program. State mutability keywords describe whether the function reads or writes persistent information. A working smart contract also needs real authorization checks when a sensitive operation should be limited to particular users. The most important distinction is that program visibility does not keep blockchain information secret.
Editor’s Note: Internal curriculum record OSSolidity.005 follows published OSSolidity.004 in the 43-subject rotation. The 1200 × 630 cover is original AI-generated oil-painting editorial artwork featuring a fictional software developer; the displayed interface is conceptual and does not prove a deployed contract, even where a simulated interface suggests deployment. The two YouTube references are identifiable third-party educational videos, not publisher recordings. Official Solidity 0.8.38 documentation grounds the technical rules. Solidity compilation, local EVM transactions, real-world security testing, player playback and mobile viewport screenshots were not independently completed. No real funds were transferred.

To donate on mobile, display the original QR on another device or use a compatible wallet’s saved-image scanner. Confirm the intended recipient 3C9o19EH5HSiwEPyCTmEKzxhNCbo2X6TTb and 5,000 satoshis before authorizing payment.
We volunteer daily to ensure the credibility of information on BitcoinVersus.Tech is Verifiably True. If you would like to support our work and help further secure the integrity of our research initiatives, please scan the QR code above.
BitcoinVersus.Tech publishes programming education for informational purposes, not audited smart-contract code, investment guidance, permission to deploy to public networks, or a substitute for independent security review.

Leave a Reply