-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Function.sol
40 lines (33 loc) · 1.01 KB
/
Function.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
40
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
contract FunctionTypes{
uint256 public number = 5;
constructor() payable {}
// 函数类型
// function (<parameter types>) {internal|external} [pure|view|payable] [returns (<return types>)]
// 默认function
function add() external{
number = number + 1;
}
// pure: 纯纯牛马
function addPure(uint256 _number) external pure returns(uint256 new_number){
new_number = _number+1;
}
// view: 看客
function addView() external view returns(uint256 new_number) {
new_number = number + 1;
}
// internal: 内部函数
function minus() internal {
number = number - 1;
}
// 合约内的函数可以调用内部函数
function minusCall() external {
minus();
}
// payable: 递钱,能给合约支付eth的函数
function minusPayable() external payable returns(uint256 balance) {
minus();
balance = address(this).balance;
}
}