Transfer contract with fees


If anyone can help me get this started or point me in the right direction I’d really appreciate it.

Example of contract: (tokenA is myToken)

  • user address sends tokenB to contract
  • contract charges fee for transaction
  • fee is added to external address (charity, LP, dev, etc…)
  • Contract collects tokenB and reads quantity
  • contract sends tokenA to user address at a 1:1 ratio of tokenB (able to change ratio)
  • contract charges fee for transaction

I’m giving tokenA in exchange for tokenB. No farming or staking. Just a simple 3rd party transfer function that charges a fee for interacting with contract (i.e. sending tokenB and receiving tokenA).

I’ve tried to work with an airdrop distributor as the idea is quite similar. Only difference is receiving the token and charging a fee. I’ve had no luck with this method.

I want to use a contract so i can automate the process for multiple users sending tokenB.

any resources, ideas or code is welcome.

maybe you can study Reflect.Finance or Safemoon smart contract. theyre charging fee at transfer.

and consider this before you create erc20:

Thank you for your reply. But this is not a safemoon/reflect clone. This is more similar to an airdrop. I cant find an example contract to learn from so I was hoping maybe someone can provide a relevant resource.

Got this from a gentleman. I believe i can work with this and that I was possibly overanalyzing it.

user sends ETH
contract takes ETH
contract does ETH.div(%) and sends to charity address
balanceOf(this) for quantity
contract does tokenA.transferFrom(amount, address)