-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyContract.sol
39 lines (31 loc) · 1.34 KB
/
MyContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: MIT
//
// https://cryptomarketpool.com/visibility
pragma solidity ^0.8.0;
contract MyContract {
// Private – A private function/state variable is only available inside the contract that defines it. It is generally good practice to keep functions private.
// Internal – A internal function/state variable is only available inside the contract that defines it AND any contracts that inherit it
// External – An external function can only be called by external contacts. Not visible inside the contract that defines it.
// Public – A public function/state variable is available to any contract or third party that wants to call it. Public is the default if visibility is not specified.
// private state variable
string private name;
uint256 internal age = 35;
string public id = "123";
// public function
function setName(string memory newName) public {
name = newName;
}
// public function
function getName() public view returns (string memory) {
return name;
}
function getAge() public view returns (uint256) {
return privateFunction();
}
function privateFunction() private view returns (uint256) {
return age;
}
function externalFunction() external pure returns (string memory) {
return "external-function";
}
}