-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySendTransfer.sol
41 lines (32 loc) · 982 Bytes
/
MySendTransfer.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
41
//SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
/*
Major difference between send() and transfer():
If the target address is a contract and the transfer fails, then .transfer will result in
an exception and .send will simply return false, but the transaction won't fail.
*/
contract Sender {
receive() external payable {}
function withdrawTransfer(address payable _to) public {
_to.transfer(10);
}
function withdrawSend(address payable _to) public {
bool sentSuccessful = _to.send(10);
require(sentSuccessful, "send failed");
}
}
contract ReceiverNoAction {
receive() external payable {}
function balance() public view returns(uint) {
return address(this).balance;
}
}
contract ReceiverAction {
uint public balanceReceived;
receive() external payable {
balanceReceived += msg.value;
}
function balance() public view returns(uint) {
return address(this).balance;
}
}