I would like to know how I can set up a “business fee” on this. Every time a user sends ETH to another user through my website using Metamask, my company would get a %.
Thank you for your question @tiago4maral . There are a few different ways for you to build this, so I’m going to outline a framework for how you can approach solving this problem, and I hope that you find the resources useful for you.
Using a Smart Contract to Extract a Fee from a Tip Amount
Context: In order to charge a business fee, you will create and deploy a smart contract that users interact with as part of sending the tip. You will write a smart contract that contains the logic necessary to send the tip to the recipient and send a fee to an address that will receive the fee.
You could write a smart contract with the following logic (this is pseudo code, but I think it may be helpful for think out what you want to do - the syntax is not perfect, so please do not copy paste this):
constructor(fee_address ) public {
fee_receiver = msg.sender;
}
//in this constructor, we are initializing an address to which the fees will be paid. This address could be an externally owned account, or it could be a smart contract. This will be depend on your use case for the fee.
function tip (address, tip_amount) {
address tipper = msg.sender;
fee = tip_amount * (0.05);
tip_minus_fee = tip_amount - fee;
tipper.transfer(tip_minus_fee);
tipper.transfer(fee);
}
//here we are creating a tip function and we are calculating the fee that needs to be taken from the tip. Then we transfer the tip to the respective addresses.
As an example, although it not a perfect one, I am going to point you to the Uniswap v2 Factory Smart Contract as a way of showing the fee structure that is implemented on a protocol level.
There is a functions within that contract that look like the following:
Also, it is important to note, if you are going to implement such a fee system - a best practice is to alert your user of the fee so they can tip the appropriate amount to cover both the tip and the fee. Let me know if you have any questions about this, or need other sources of inspiration.