Created
March 6, 2019 06:36
-
-
Save siburu/3bf4c340b39e63fbf0057c7a0e8e7fa6 to your computer and use it in GitHub Desktop.
How to implement gas-free tx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.5.0; | |
contract Refunder { | |
modifier fullyRefund() { | |
uint256 gas = gasleft(); | |
_; | |
gas = gas - gasleft() + 21000; | |
msg.sender.transfer(gas * tx.gasprice); | |
} | |
function withRefund() external fullyRefund { | |
doHeavy(); | |
} | |
function withoutRefund() external { | |
doHeavy(); | |
} | |
function doHeavy() private { | |
for (uint x = 0; x < 10000; x++) {} | |
} | |
function () external payable {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment