Skip to content

Commit

Permalink
Merge pull request #509 from Yumistar/patch-28
Browse files Browse the repository at this point in the history
Update He​len.md
  • Loading branch information
SunWeb3Sec authored Oct 16, 2024
2 parents 0e1bf74 + db9adbb commit c01c934
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions He​len.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

---
timezone: Asia/Shanghai
---
Expand All @@ -15,6 +16,49 @@ timezone: Asia/Shanghai
## Notes

<!-- Content_START -->
### 2024.10.16
2. internal v.s. external
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
contract FunctionTypes{
uint256 public number = 5;
// 默认function
function add() external{
number = number + 1;
}
// pure: 纯纯牛马
function addPure(uint256 _number) external pure returns(uint256 new_number){
new_number = _number + 1;
}
// internal: 内部函数
function minus() internal {
number = number - 1;
}
// 合约内的函数可以调用内部函数
function minusCall() external {
minus();
}
// 合约内的函数可以调用内部函数
function minusCall() external {
minus();
}
// payable: 递钱,能给合约支付eth的函数
function minusPayable() external payable returns(uint256 balance) {
minus();
balance = address(this).balance;
}
}
```
我們定義一個函數internal,minus()每次調用使得變數減number1 。internalexternalminusCall()minus()

3.應付
定義一個external payable函數minusPayable(),引用的調用,並且返回合約minus()裡的ETH餘額(this關鍵字可以讓我們引用合約位址)。minusPayable()



### 2024.10.12
實作
```solidity
Expand Down

0 comments on commit c01c934

Please sign in to comment.