Skip to content

Instantly share code, notes, and snippets.

@akinncar
Last active November 6, 2022 22:56
Show Gist options
  • Save akinncar/e6ac62dd9baedc8b4c60dfa2ae13565f to your computer and use it in GitHub Desktop.
Save akinncar/e6ac62dd9baedc8b4c60dfa2ae13565f to your computer and use it in GitHub Desktop.
//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