Last active
November 6, 2022 22:56
-
-
Save akinncar/e6ac62dd9baedc8b4c60dfa2ae13565f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.0; | |
contract CashbackContract { | |
address payable shop; | |
uint256 public percentage = 10; // 10% | |
constructor(address target) { | |
shop = payable(target); | |
} | |
receive() payable external { | |
uint cashback = msg.value * percentage / 100; | |
uint finalValue = msg.value - cashback; | |
(bool successTx,) = shop.call{value: finalValue}(""); | |
require(successTx, "Failed to send money"); | |
(bool successCashback,) = msg.sender.call{value: cashback}(""); | |
require(successCashback, "Failed to cashback"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment