I am new to this topic. I'm trying to implement a method to split the payment inside the token contract itself. I know that there is a separate contract for payment splitting, but I want to try to implement it inside token contract.
I've written such a method. Could you please tell me:
- Is it safe to make the payment this way?
- Is it possible to implement in any other way (but inside token contract itself)?
function splitPayment(address from, address firstReceiver, address secondReceiver, uint256 amount) public {
require(from != address(0), "ERC20: transfer from the zero address");
require(firstReceiver != address(0), "ERC20: transfer to the zero address");
require(secondReceiver != address(0), "ERC20: transfer to the zero address");
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[firstReceiver] += amount * 70 / 100;
_balances[secondReceiver] += amount * 30 / 100;
emit SplittedTransfer(from, firstReceiver, secondReceiver, amount);
}