Skip to content

Commit 77f5435

Browse files
authored
docs(codespell): fix codespell (#859)
fix codespell
1 parent 2d5782c commit 77f5435

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

Languages/en/20_SendETH_en/SendETH.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pragma solidity ^0.8.21;
77
// call: all gas, return (bool, data)
88

99
error SendFailed(); // error when sending with Send
10-
error CallFailed(); // error when seding with Call
10+
error CallFailed(); // error when sending with Call
1111

1212
contract SendETH {
1313
// Constructor, make it payable so we can transfer ETH at deployment

Languages/en/20_SendETH_en/readme.md

+30-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ tags:
99

1010
# WTF Solidity Tutorial: 20. Sending ETH
1111

12-
Recently, I have been revisiting Solidity, consolidating the finer details, and writing "WTF Solidity" tutorials for newbies.
12+
Recently, I have been revisiting Solidity, consolidating the finer details, and writing "WTF Solidity" tutorials for newbies.
1313

1414
Twitter: [@0xAA_Science](https://twitter.com/0xAA_Science) | [@WTFAcademy_](https://twitter.com/WTFAcademy_)
1515

@@ -18,9 +18,10 @@ Community: [Discord](https://discord.gg/5akcruXrsk)|[Wechat](https://docs.goog
1818
Codes and tutorials are open source on GitHub: [github.com/AmazingAng/WTF-Solidity](https://github.com/AmazingAng/WTF-Solidity)
1919

2020
-----
21-
There are three ways of sending `ETH` in `Solidity`: `transfer()`, `send()` and `call()`, in which `call()` is recommended.
21+
There are three ways of sending `ETH` in `Solidity`: `transfer()`, `send()` and `call()`, in which `call()` is recommended.
2222

2323
## Contract of Receiving ETH
24+
2425
Let's deploy a contract `ReceiveETH` to receive `ETH`. `ReceiveETH` has an event `Log`, which logs the received `ETH` amount and the remaining `gas`. Along with two other functions, one is the `receive()` function, which is executed when receiving `ETH`, and emits the `Log` event; the other is the `getBalance()` function that is used to get the balance of the contract.
2526
```solidity
2627
contract ReceiveETH {
@@ -39,12 +40,13 @@ contract ReceiveETH {
3940
}
4041
```
4142

42-
After deploying `ReceiveETH`, call the `getBalance()` function, we can see the balance is `0 Ether`.
43+
After deploying `ReceiveETH`, call the `getBalance()` function, we can see the balance is `0 Ether`.
4344

4445
![20-1](./img/20-1.png)
4546

4647
## Contract of Sending ETH
4748
We will implement three ways to send `ETH` to the `ReceiveETH` contract. First thing first, let's make the `constructor` of the `SendETH` contract `payable`, and add the `receive()` function, so we can transfer `ETH` to our contract at deployment and after.
49+
4850
```solidity
4951
contract SendETH {
5052
// constructor, make it payable so we can transfer ETH at deployment
@@ -53,39 +55,43 @@ contract SendETH {
5355
receive() external payable{}
5456
}
5557
```
58+
5659
### transfer
60+
5761
- Usage: `receiverAddress.transfer(value in Wei)`.
5862
- The `gas` limit of `transfer()` is `2300`, which is enough to make the transfer, but not if the receiving contract has a gas-consuming `fallback()` or `receive()`.
59-
- If `transfer()` fails, the transaction will `revert`.
63+
- If `transfer()` fails, the transaction will `revert`.
6064

6165
Sample code: note that `_to` is the address of the `ReceiveETH` contract, and `amount` is the value you want to send.
66+
6267
```solidity
6368
// sending ETH with transfer()
6469
function transferETH(address payable _to, uint256 amount) external payable{
6570
_to.transfer(amount);
6671
}
6772
```
6873

69-
After deploying the `SendETH` contract, we can send `ETH` to the `ReceiveETH` contract. If `amount` is 10, and `value` is 0, `amount`>`value`, the transaction fails and gets `reverted`.
74+
After deploying the `SendETH` contract, we can send `ETH` to the `ReceiveETH` contract. If `amount` is 10, and `value` is 0, `amount`>`value`, the transaction fails and gets `reverted`.
7075

7176
![20-2](./img/20-2.png)
7277

73-
If `amount` is 10, and `value` is 10, `amount`<=`value`, then the transaction will go through.
78+
If `amount` is 10, and `value` is 10, `amount`<=`value`, then the transaction will go through.
7479

7580
![20-3](./img/20-3.png)
7681

77-
In the `ReceiveETH` contract, when we call `getBalance()`, we can see the balance of the contract is `10` Wei.
82+
In the `ReceiveETH` contract, when we call `getBalance()`, we can see the balance of the contract is `10` Wei.
7883

7984
![20-4](./img/20-4.png)
8085

8186
### send
8287

83-
- Usage: `receiverAddress.send(value in Wei)`.
84-
- The `gas` limit of `send()` is `2300`, which is enough to make the transfer, but not if the receiving contract has a gas-consuming `fallback()` or `receive()`.
85-
- If `send()` fails, the transaction will not be `reverted`.
86-
- The return value of `send()` is `bool`, which is the status of the transaction, you can choose to act on that.
88+
- Usage: `receiverAddress.send(value in Wei)`.
89+
- The `gas` limit of `send()` is `2300`, which is enough to make the transfer, but not if the receiving contract has a gas-consuming `fallback()` or `receive()`.
90+
- If `send()` fails, the transaction will not be `reverted`.
91+
- The return value of `send()` is `bool`, which is the status of the transaction, you can choose to act on that.
8792

8893
Sample Code:
94+
8995
```solidity
9096
// sending ETH with send()
9197
function sendETH(address payable _to, uint256 amount) external payable{
@@ -97,22 +103,23 @@ function sendETH(address payable _to, uint256 amount) external payable{
97103
}
98104
```
99105

100-
Now we send `ETH` to the `ReceiveETH` contract, if `amount` is 10, and `value` is 0, `amount`>`value`, the transaction fails, since we handled the return value, the transaction will be `reverted`.
106+
Now we send `ETH` to the `ReceiveETH` contract, if `amount` is 10, and `value` is 0, `amount`>`value`, the transaction fails, since we handled the return value, the transaction will be `reverted`.
101107

102108
![20-5](./img/20-5.png)
103109

104-
If `amount` is 10, and `value` is 11, `amount`<=`value`, the transaction is successful.
110+
If `amount` is 10, and `value` is 11, `amount`<=`value`, the transaction is successful.
105111

106112
![20-6](./img/20-6.png)
107113

108114
### call
109115

110-
- Usage: `receiverAddress.call{value: value in Wei}("")`.
111-
- There is no `gas` limit for `call()`, so it supports more operations in `fallback()` or `receive()` of the receiving contract.
112-
- If `call()` fails, the transaction will not be `reverted`.
113-
- The return value of `call()` is `(bool, data)`, in which `bool` is the status of the transaction, you can choose to act on that.
116+
- Usage: `receiverAddress.call{value: value in Wei}("")`.
117+
- There is no `gas` limit for `call()`, so it supports more operations in `fallback()` or `receive()` of the receiving contract.
118+
- If `call()` fails, the transaction will not be `reverted`.
119+
- The return value of `call()` is `(bool, data)`, in which `bool` is the status of the transaction, you can choose to act on that.
114120

115121
Sample Code:
122+
116123
```solidity
117124
// sending ETH with call()
118125
function callETH(address payable _to, uint256 amount) external payable{
@@ -124,22 +131,21 @@ function callETH(address payable _to, uint256 amount) external payable{
124131
}
125132
```
126133

127-
Now we send `ETH` to the `ReceiveETH` contract, if `amount` is 10, and `value` is 0, `amount`>`value`, the transaction fails, since we handled the return value, the transaction will be `reverted`.
134+
Now we send `ETH` to the `ReceiveETH` contract, if `amount` is 10, and `value` is 0, `amount`>`value`, the transaction fails, since we handled the return value, the transaction will be `reverted`.
128135

129136
![20-7](./img/20-7.png)
130137

131-
If `amount` is 10, and `value` is 11, `amount`<=`value`, the transaction is successful.
138+
If `amount` is 10, and `value` is 11, `amount`<=`value`, the transaction is successful.
132139

133140
![20-8](./img/20-8.png)
134141

135142
With any of these three methods, we send `ETH` to the `ReceiveETH` contract successfully.
136143

137144
## Summary
145+
138146
In this tutorial, we talked about three ways of sending `ETH` in `solidity`:
139-
`transfer`, `send` and `call`.
147+
`transfer`, `send` and `call`.
148+
140149
- There is no `gas` limit for `call`, which is the most flexible and recommended way;
141150
- The `gas` limit of `transfer` is `2300 gas`, transaction will be `reverted` if it fails, which makes it the second choice;
142-
- The `gas` limit of `send` is `2300`, the transaction will not be `reverted` if it fails, which makes it the worst choice.
143-
144-
145-
151+
- The `gas` limit of `send` is `2300`, the transaction will not be `reverted` if it fails, which makes it the worst choice.

0 commit comments

Comments
 (0)