Why fee-on-transfer tokens need special handling

A standard ERC20 transfer is simple: if you send 100 tokens, the recipient receives 100. Fee-on-transfer tokens are different. For example:

  • the sender transfers 100
  • the token contract burns 2
  • the recipient receives 98

If your contract credits a user with 100 after calling transferFrom(), it will overstate the funds it actually holds. That can lead to:

  • failed withdrawals later
  • unfair accounting between payees
  • stuck balances
  • silent underpayment

The safest approach is to treat the contract’s token balance as the source of truth and compute the actual received amount from balance deltas.


Design goals

A robust fee-on-transfer payment splitter should:

  • accept deposits in a specified ERC20 token
  • record each payee’s share in basis points
  • account for the actual amount received, not the requested amount
  • let users claim their accumulated balance
  • avoid reentrancy issues during claims
  • support tokens that charge transfer fees on both incoming and outgoing transfers

This tutorial uses a pull-based model: deposits are recorded once, and each payee claims their own share later. That keeps the contract simple and reduces operational risk.


Core accounting model

Instead of assigning a fixed amount per deposit, we track:

  • totalReceived: the cumulative amount actually received by the contract
  • released[account]: how much a payee has already claimed
  • shares[account]: the payee’s relative entitlement
  • totalShares: the sum of all shares

When a deposit arrives, the contract measures the token balance before and after transferFrom(). The difference is the real amount received. Each payee can then claim:

entitled = totalReceived * shares[account] / totalShares
claimable = entitled - released[account]

This works even if the token charges a fee on deposit, because the contract only distributes what it truly holds.


Example contract

Below is a complete example using OpenZeppelin-style interfaces and guards.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface IERC20 {
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

abstract contract ReentrancyGuard {
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;
    uint256 private _status = _NOT_ENTERED;

    modifier nonReentrant() {
        require(_status != _ENTERED, "REENTRANCY");
        _status = _ENTERED;
        _;
        _status = _NOT_ENTERED;
    }
}

contract FeeOnTransferPaymentSplitter is ReentrancyGuard {
    IERC20 public immutable token;

    address[] private _payees;
    mapping(address => uint256) public shares;
    mapping(address => uint256) public released;

    uint256 public totalShares;
    uint256 public totalReceived;

    event Deposited(address indexed from, uint256 requestedAmount, uint256 receivedAmount);
    event PaymentReleased(address indexed to, uint256 amount);

    constructor(address tokenAddress, address[] memory payees, uint256[] memory payeeShares) {
        require(tokenAddress != address(0), "TOKEN_ZERO");
        require(payees.length > 0, "NO_PAYEES");
        require(payees.length == payeeShares.length, "LENGTH_MISMATCH");

        token = IERC20(tokenAddress);

        for (uint256 i = 0; i < payees.length; i++) {
            address account = payees[i];
            uint256 share = payeeShares[i];

            require(account != address(0), "PAYEE_ZERO");
            require(share > 0, "SHARE_ZERO");
            require(shares[account] == 0, "DUPLICATE_PAYEE");

            _payees.push(account);
            shares[account] = share;
            totalShares += share;
        }
    }

    function payees() external view returns (address[] memory) {
        return _payees;
    }

    function deposit(uint256 amount) external nonReentrant {
        require(amount > 0, "AMOUNT_ZERO");

        uint256 beforeBalance = token.balanceOf(address(this));
        require(token.transferFrom(msg.sender, address(this), amount), "TRANSFER_FROM_FAILED");
        uint256 afterBalance = token.balanceOf(address(this));

        require(afterBalance >= beforeBalance, "BALANCE_UNDERFLOW");

        uint256 received = afterBalance - beforeBalance;
        require(received > 0, "NO_TOKENS_RECEIVED");

        totalReceived += received;

        emit Deposited(msg.sender, amount, received);
    }

    function pendingPayment(address account) public view returns (uint256) {
        uint256 accountShares = shares[account];
        if (accountShares == 0 || totalShares == 0) {
            return 0;
        }

        uint256 entitled = (totalReceived * accountShares) / totalShares;
        if (entitled <= released[account]) {
            return 0;
        }

        return entitled - released[account];
    }

    function release() external nonReentrant {
        uint256 payment = pendingPayment(msg.sender);
        require(payment > 0, "NOTHING_TO_RELEASE");

        released[msg.sender] += payment;

        require(token.transfer(msg.sender, payment), "TRANSFER_FAILED");

        emit PaymentReleased(msg.sender, payment);
    }

    function releaseTo(address account) external nonReentrant {
        uint256 payment = pendingPayment(account);
        require(payment > 0, "NOTHING_TO_RELEASE");

        released[account] += payment;

        require(token.transfer(account, payment), "TRANSFER_FAILED");

        emit PaymentReleased(account, payment);
    }
}

How the contract works

1. Initialization

The constructor receives:

  • the ERC20 token address
  • a list of payees
  • a parallel list of share values

Shares are immutable after deployment in this example. That keeps the math predictable and avoids governance complexity.

2. Depositing funds

The deposit() function measures the contract balance before and after transferFrom(). This is the critical step. If the token charges a 3% fee, a request for 1,000 tokens may only increase the contract balance by 970. The contract records 970 as the distributable amount.

3. Claiming funds

Each payee can call release() to withdraw their accumulated entitlement. The contract computes the claimable amount from the total received so far, subtracts what has already been released, and transfers the remainder.

4. Why release updates state before transfer

The contract increments released[msg.sender] before calling transfer(). This follows the checks-effects-interactions pattern and reduces reentrancy risk. Even if the token tries to invoke external code during transfer, the claim state is already updated.


Handling outgoing transfer fees

Some fee-on-transfer tokens also tax outgoing transfers from the splitter contract. That means a payee may receive slightly less than the amount the contract sends.

There are two common approaches:

ApproachBehaviorTradeoff
Assume standard ERC20 behaviorContract sends the full claim amountRecipient may receive less than expected if the token taxes outgoing transfers
Measure post-transfer balanceContract verifies the recipient’s received amountMore complex and still token-specific

For most payment splitters, the first approach is acceptable if the token’s transfer tax is known and documented. If exact recipient delivery is required, fee-on-transfer tokens are a poor fit and you should use a non-taxed settlement asset instead.


Best practices for production use

Use a trusted token list

Do not assume every ERC20 behaves the same. Restrict deposits to tokens you have reviewed, or deploy one splitter per token. Fee mechanics vary widely, and some tokens are non-standard in ways that break generic integrations.

Avoid mutable share changes unless necessary

Changing shares after deposits creates fairness issues. If you must support updates, define a clear policy:

  • freeze withdrawals during reconfiguration
  • snapshot balances before changing shares
  • emit events for every update
  • document how past deposits are treated

A simpler alternative is to deploy a new splitter for each distribution cycle.

Prefer pull over push

Push-based distribution loops over all payees and transfers funds in one transaction. That becomes fragile as the number of payees grows and can fail if one recipient reverts. Pull-based claims scale better and isolate failures.

Emit precise events

Events are essential for off-chain accounting and analytics. In this pattern, Deposited should include both the requested amount and the actual received amount so indexers can reconcile fee deductions.

Consider rounding behavior

Integer division truncates remainders. Over many deposits, tiny dust amounts can accumulate in the contract. That is normal. You can leave dust for the last claimant, sweep it to a treasury, or expose a separate admin-controlled dust recovery function if your policy allows it.


Common pitfalls

Using the requested amount instead of the received amount

This is the most serious mistake. If you record the nominal deposit amount, the contract will promise more than it owns whenever the token charges a fee.

Forgetting to validate zero-share payees

A payee with zero shares should not be allowed. It adds noise and can confuse downstream tooling.

Allowing duplicate payees

If the same address appears twice in the constructor list, the share math becomes ambiguous. Reject duplicates during deployment.

Ignoring non-standard ERC20 return values

Some tokens return false instead of reverting on failure. Always check the return value of transfer() and transferFrom().

Using transfer() for ETH-style assumptions

ERC20 tokens are not Ether. Do not assume gas stipend behavior or fallback semantics from native currency patterns. Token contracts can be more variable and less predictable.


Extending the pattern

You can adapt this splitter in several useful ways:

  • Per-deposit metadata: attach an order ID or invoice reference to each deposit event
  • Role-gated deposits: restrict deposits to approved operators
  • Time-based vesting: release only a percentage of each payee’s entitlement over time
  • Multi-token support: deploy one splitter per token, or maintain separate accounting per asset
  • Treasury fee extraction: route a fixed share to protocol treasury before computing user claims

If you add complexity, keep the accounting model explicit. The safest systems are the ones that can explain every token unit at any point in time.


Testing strategy

A fee-on-transfer splitter should be tested with at least three token behaviors:

  1. Standard ERC20: no transfer fee
  2. Incoming fee token: deposit transfers are taxed
  3. Incoming and outgoing fee token: both deposit and claim transfers are taxed

Useful test cases include:

  • deposit of 1,000 tokens with a 2% fee
  • two payees with unequal shares
  • repeated deposits followed by partial claims
  • rounding edge cases with small amounts
  • reentrancy attempts during release()

A good invariant is:

contract balance + totalReleased + burned/fee amounts == total net deposits

The exact formula depends on the token’s fee model, but the contract should never distribute more than it has actually received.


Summary

Fee-on-transfer tokens require balance-based accounting, not nominal amount accounting. A safe payment splitter should measure actual received tokens, track cumulative entitlements, and let each payee claim their share independently. This design is simple, scalable, and much less error-prone than push-based distribution.

When used with a known token and clear accounting rules, the pattern is a practical foundation for revenue sharing and on-chain payout systems.

Learn more with useful resources