-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgasLeft.sol
More file actions
26 lines (20 loc) · 805 Bytes
/
Copy pathgasLeft.sol
File metadata and controls
26 lines (20 loc) · 805 Bytes
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
// SPDX-License-Identifier: MIT
/**
gasleft() is used to prevent :
- out-of-gas errors
- calculating solidity code execution cost
- forwarding remaining gas to implementation contracts
- for preventing relayer DOS
*/
pragma solidity ^0.8.19;
contract ValidateGasTransfer{
uint constant MINIMUM_GAS_REQUIRED = 10_000;
receive() external payable {}
function trasnferEther(address[] calldata users) external {
for (uint i = 0; i < users.length; i++) {
payable(users[i]).transfer(1 ether);
if (gasleft() < MINIMUM_GAS_REQUIRED) break;
}
}
}
// Warning : Above code is only for illustration purposes, as any of the reciever's address if turns out to be a malicious smart contract can reverts the receiving ether.