Skip to content

Instantly share code, notes, and snippets.

@duanescarlett
Created March 5, 2023 17:03
Show Gist options
  • Save duanescarlett/ce7a85a26f63eefe5e9a8c8c073c929c to your computer and use it in GitHub Desktop.
Save duanescarlett/ce7a85a26f63eefe5e9a8c8c073c929c to your computer and use it in GitHub Desktop.
A smart contract that describes visibility
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
contract Visibility {
uint256 private x = 0;
uint256 internal y = 1;
uint256 public z = 2;
// Public
// Accesed from any smart contract, function inside
// its smart contract and web3 script
function publicFunction() public pure returns (uint256) {
}
// Private
// Accesed only from within the contract
function privateFunction() private pure returns (uint256) {
}
// Internal
// Accessed only from within the contract & child contracts
function internalFunction() internal pure returns (uint256) {
}
// External
// Accessed only from any contract & web3 script
// but not from an internal function
function externalFunction() external pure returns (uint256) {
}
function demo() external pure {
privateFunction();
internalFunction();
publicFunction();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment