Skip to content

Instantly share code, notes, and snippets.

@siburu
Created March 6, 2019 06:36
Show Gist options
  • Save siburu/3bf4c340b39e63fbf0057c7a0e8e7fa6 to your computer and use it in GitHub Desktop.
Save siburu/3bf4c340b39e63fbf0057c7a0e8e7fa6 to your computer and use it in GitHub Desktop.
How to implement gas-free tx
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