-
Notifications
You must be signed in to change notification settings - Fork 0
/
ether.sol
32 lines (27 loc) · 861 Bytes
/
ether.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
// 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==true, "Send failure");
}
function sendViaCall(address payable _to) external payable{
(bool success, ) = _to.call{value: 123}("");
require(success, "call failure");
}
}
contract EthReceiver{
event Log(uint amount, uint gas);
receive() external payable {
emit Log(msg.value, gasleft());
}
}