I’ll try to keep this short. I’ve been working on a project for a couple months and am creating the final tax feature it needs. I’ve got something that will take the project token in as tax although I’d like to take in ETH instead, this way the project token price isn’t hurt when we sell it for operating expenses. I’ll leave the relevant lines of code and hopefully someone smarter than me can point me in the right direction as nothing I’ve tried has worked:
pragma solidity ^0.8.20;
import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;
contract TaxFeature is ERC20 {
address public immutable fund;
constructor(address fund_) ERC20("TaxFeature", "Tax") {
fund = fund_;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual override {
uint tax = (amount / 100) * 2; // 2% tax
super._transfer(sender, recipient, amount - tax);
super._transfer(sender, fund, tax);
}
}