React - How do I implant msg.value in this2

Using some code I found online I was able to do some stuff (In this case Approve....) But is there any way I can add a "fee" to this say 1 ether which will be sent to a specific address?

const transferHandler = async (e) => {
		e.preventDefault();
		let transferAmount = e.target.sendAmount.value;
		let recieverAddress = e.target.recieverAddress.value;

		let txt = await props.contract.approve(recieverAddress, transferAmount);
		console.log(txt);
		setTransferHash("Transfer confirmation hash: " + txt.hash);
	        }

Can I set a "let fee = 1; and include this in the let txt = await props.con.......?

Charging fees in the front end is bad practice.
Charging fee on an approval is Worst.

When you transfer a token the call is sent to the token contract that moves the token. Any msg.value sent with your transfer will go to the token contract.

The correct way to do this would be to call a function that is payable and deal with the value it received.

1 Like