I am trying to create a solution that charges a processing fee when ERC20 payments go from user to user on our platform. I don't control the ERC20 token so I can't implement anything on that contract.
- User1 sends full payment
- User2 receives (payment - fee)
- Treasury receives the fee
This was really easy to implement for ETH or MATIC payments with a Solidity contract.
With ERC20 tokens, I am struggling a lot:))
What I have tried so far:
Multiple instructions in one transaction (like on Solana)
Couldn't find any way to do this with Etherjs, and several online resources mentioned it doesn't work.
Openzeppelin PaymentSplitter contract or a variation
problem: when sending the payment (using the token's ERC20 contract), it's not possible to send the destination wallet. So the payment splitter can only be used for wallets that were saved on contract creation.
Custom contract using ERC20 transferFrom method
This is the closest that I have been able to get. However, it still requires 2 transactions from the user (one to approve, and the other to call the custom contract method).
Any ideas are greatly appreciated!