ERC-4393 A tip token standard for NFT holders (Micropayments for NFTs and Multi Tokens)
Stagnant · NFTs & multi-token · created 2021-10-24
A standard interface that lets anyone send small donations (tips) to holders of an NFT or EIP-1155 multi-token, which holders can then withdraw as ERC-20 rewards.
Why it is needed
Currently there is no set way to send small donations to NFT or multi-token holders, so every app must build its own ad hoc donation structure. Sending tips as individual transactions one at a time makes gas costs too high, making small donations inefficient in themselves. In addition, when a single token is split among multiple holders as in EIP-1155, there is no defined basis for how rewards should be divided. Without a common specification, incompatible contracts end up being built separately for each distinct use case, such as in-game purchases, content support, fundraising, royalty distribution, ad rewards, and reward cards, and it also becomes difficult for wallets or explorers to track donation history.
What to implement
function deposit(address user, uint256 amount) external payable;: Deposits an ERC-20-compatible token and receives an equivalent amount of tip tokens.function withdrawReward(uint256 amount) external payable;: An NFT holder withdraws accumulated rewards whenever desired.function balanceOf(address user) external view returns (uint256);: Queries the tip token balance held by a user.function balanceDepositOf(address user) external view returns (uint256);: Queries the amount a user has deposited that has not yet been spent as tips.function rewardPendingOf(address holder) external view returns (uint256);: Queries the reward amount accumulated for a holder that has not yet been paid out.
In depth
The ITipToken interface and EIP-165 identification
A contract implementing this standard must implement every function in the interface and emit every defined event, so that the contract's entire state can be reconstructed from events alone. EIP-165's supportsInterface must return true when given the interfaceID 0xE47A7022. The ApprovalForNFT event itself has a separately specified ERC-165 identifier, 0x985A3267. In the code and documentation, nft may also refer to an EIP-1155 multi-token.
Approving tip receipt (setApprovalForNFT, isApprovalForNFT)
setApprovalForNFT must revert if nft's supportsInterface does not return true for either IERC721 or IERC1155, and must also revert if any of the holders is the zero address, or if nft has not approved the tip token contract as an operator. It must emit the ApprovalForNFT event after processing. isApprovalForNFT only checks whether a holder and NFT were previously approved; it does not check whether the actual holder has since changed, which is left to implementers to handle by detecting ownership change events.
Behavioral rules for tip and tipBatch
The tip function must revert if nft has not been approved to receive tips or is the zero address, and must burn the tip amount while accumulating the reward for the holder. If it is a multi-token with multiple holders, the tip must be split among them according to their holding ratio, and a Tip event must be emitted after processing. tipBatch requires that all input arrays have the same length, that no user address is the zero address, must revert the entire batch if even one error occurs, and must emit Tip events so that it can be reconstructed who sent how much to which NFT.
The formula for calculating tip token value
The reward value transferred when sending a tip is calculated by multiplying the user's total deposited balance by the tip amount and dividing by the user's total tip token balance. As a result, adding freely received tips to a user's balance only dilutes the value per tip, while the total deposited value the user represents remains unchanged. If the tip token contract inherits EIP-20, tips can also be transferred directly between users; if it does not inherit EIP-20, it must emit Transfer events on minting and burning, with from as the zero address for mints and to as the zero address for burns.
Royalty distribution using EIP-1155
EIP-1155 allows a single token ID to be split across multiple holders. For example, for a token ID representing an article written by several contributors, each contributor's balance determines their distribution share. If holder A's balance is 25 and holder B's balance is 75, a tip sent to this token accrues as pending reward at 25 percent to A and 75 percent to B. In implementations that send royalties directly to holders, the tip function could be built to transfer the royalty amount, net of fees, straight from the user's account to the holder.
Deposit and withdrawal (withdrawReward)
Each tip token contract must handle only one type of ERC-20-compatible deposit token at a time, and supporting multiple types requires deploying a separate contract per type. The ERC-20 token address to be used as the reward must be passed in the constructor or initialize method, and reverting is recommended if it is the zero address. deposit must emit a Deposit event after processing. withdrawReward must revert if the pending balance is insufficient for the amount being withdrawn, and on success must send the amount to the holder, reduce the pending balance, and emit a WithdrawReward event.
Reducing gas costs through batching
Collecting tips off-chain and calling tipBatch once means the transaction initialization cost is paid only once. Summing multiple tips from the same user to the same NFT off-chain and sending them as a single batch entry saves further, and grouping users sending to the same NFT means the check for whether that NFT is EIP-721 or EIP-1155 only needs to be performed once per group. Whatever optimization is applied, it must remain possible to reconstruct who sent how much to whom via which NFT from the Tip and TipBatch events.
Backward compatibility and proposal status
If the tip token contract inherits EIP-20, functions like transfer can be used as is, and it is recommended that balanceOf simply call the parent contract's balanceOf. However, a spender function that would let other users spend someone else's tips is not included in this standard. This proposal is currently Stagnant, a draft that is no longer being discussed and has stalled.
Things to watch out for
- Deposit protection cannot be enforced: It is recommended that a user's deposit be locked in the tip token contract or an external escrow and not used for anything other than rewards, but the standard cannot enforce this. However, when a holder withdraws, the reward must be payable from the deposit pool at that time.
- Approval required before sending a tip: Before a user can tip an NFT, the holder must first grant tip-receiving approval from the tip token contract.
- Reward recipients and fees must be transparent: It must be unambiguous in the contract code that the holder is the one receiving the reward, and if there is a fee, the user must be able to clearly see it before depositing.
- Risk of revenue stream hijacking: There is a risk that a malicious implementer could try to hijack the tip revenue stream, but given how frequent and numerous tip transactions are, such fraud tends to surface relatively quickly.