Skip to content

Instantly share code, notes, and snippets.

@pcaversaccio
Created April 24, 2023 12:48
Show Gist options
  • Save pcaversaccio/67e7335126f19d6a2fb4acaab209e37b to your computer and use it in GitHub Desktop.
Save pcaversaccio/67e7335126f19d6a2fb4acaab209e37b to your computer and use it in GitHub Desktop.
Always remember that `address(this).balance` includes also `msg.value` of the current transaction.
// SPDX-License-Identifier: WTFPL
pragma solidity ^0.8.19;
contract TryToReachMe {
constructor() payable {
assert(msg.value == 1 wei);
}
function tryMeBabe(address addr) public payable {
uint256 balance = address(this).balance;
if (msg.value > balance) {
unchecked {
payable(addr).transfer(balance + msg.value);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment