-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendEth.sol
50 lines (44 loc) · 1.36 KB
/
SendEth.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
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/*
withdraw ETH without msg.value:
syntax:
addressContract.withdraw(amount);
example:
IWETH(WETH).withdraw(amountETH);
deposit ETH without msg.value:
syntax:
addressContract.deposit {value: amount}();
example:
IWETH(WETH).deposit{value: amount}();
call contract ETH without msg.value:
syntax:
addressContract.call{value: amount}();
*/
contract SendEther {
constructor() payable {}
receive() external payable {}
function sendViaTransfer(address payable to, uint256 amount) public payable {
to.transfer(amount);
}
function sendViaSend(address payable to, uint256 amount) public payable {
bool sent = to.send(amount);
require(sent, "Failed to send Ether");
}
function sendViaCall(address payable to, uint256 amount) public payable {
(bool sent, bytes memory data) = to.call{value: amount}("");
require(sent, "Failed to send Ether");
}
}
contract EthReceiver {
event Log (uint256 amount, uint gas);
receive() external payable {
emit Log (msg.value, gasleft());
}
}
contract EthFallback {
event Log (uint gas);
fallback() external payable {
emit Log (gasleft());
}
}