Created
March 5, 2023 17:03
-
-
Save duanescarlett/ce7a85a26f63eefe5e9a8c8c073c929c to your computer and use it in GitHub Desktop.
A smart contract that describes visibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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