-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendEther.sol
35 lines (27 loc) · 832 Bytes
/
SendEther.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
// 3 ways to send ETH
// transfer - 2300 gas, reverts
// send - 2300 gas, returns bool
// call - all gas, returns bool and data
contract SendEther {
constructor() payable {}
receive() external payable {}
function sendViaTransfer(address payable _to) external payable {
_to.transfer(123);
}
function sendViaSend(address payable _to) external payable {
bool sent = _to.send(123);
require(sent, "Send Failed!");
}
function sendViaCall(address payable _to) external payable {
(bool success, ) = _to.call{value: 123}("");
require(success, "Call Failed!");
}
}
contract EthReceiver {
event Log(uint amount, uint gas);
receive() external payable {
emit Log(msg.value, gasleft());
}
}