Specialized Tax Token

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);
}

}

Hi @XXI

Are you having any error from coded? or Is it just logic issue?

It’s just the logic, I think to take in ETH (or whatever the native token of the chain is) I would have to implement an approve function for eth and calculate 2% of project token they purchased into eth and transfer that with the _transfer function in this code

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.