I have a token named TEST that integrates a function called addFund.

This addFund function is responsible for receiving a 3% fee from every buy/sell of the token. The total fee is 5%: 1% for LP (liquidity pool) and 1% for the team wallet. There is no problem with that. The issue arises when a transfer occurs and addFund is triggered, resulting in the error message "Transfer amount must be greater than zero."

Code for Token:https://mumbai.polygonscan.com/address/0xc7cd934810eda1720f631b1381b36176ed0d69f6#code

code function for addFund:

/// @notice handles transfers, budget adjustment and commission calculation.
  /// @param token is the token to be allocated.
  /// @param amount is the amount to be allocated.
  function _handleAddFunds(IERC20 token, uint256 amount) private {
    // calculate commission
    uint256 commission = (amount * commissionBp) / BASE;
    uint256 amountLeft = amount - commission;

    // transfer commission to postmint.
    uint256 commissionBefore = token.balanceOf(postmint);
    token.safeTransferFrom(msg.sender, postmint, commission);
    uint256 commissionAfter = token.balanceOf(postmint);
    if (commissionAfter - commissionBefore != commission) {
      revert BadCommissionTransfer();

    // transfer the amount left to the campaign.
    uint256 amountLeftBefore = token.balanceOf(address(this));
    token.safeTransferFrom(msg.sender, address(this), amountLeft);
    uint256 amountLeftAfter = token.balanceOf(address(this));
    if (amountLeftAfter - amountLeftBefore != amountLeft) {
      revert BadFundsTransfer();

    uint256 budget = budgets[token];
    budget += amountLeft;
    budgets[token] = budget;

/// @notice transfers {_tokens, amounts} for each token, amount pair provided from the tx sender to the campaign address
  /// while taking commission for postmint.
  /// @param funds defines the tokens and amounts to transfer, they MUST be part of the tokens supported by the campaign.
  /// @dev this function transfers amounts[i] for tokens[i] to the campaign.
  /// The number of tokens MUST match the number of amounts.
  function addFunds(Funds[] calldata funds) public onlyOwner {
    uint256 fundsLen = funds.length;
    if (fundsLen == 0) {
      revert NoFundsProvided();
    for (uint256 i = 0; i < fundsLen; ) {
      bool supported = supportedToken(funds[i].token);
      if (!supported) {
        revert UnsupportedToken(address(funds[i].token));
      if (funds[i].amount == 0) {
        revert NoAmountProvided();
      _handleAddFunds(funds[i].token, funds[i].amount);

      unchecked {
    emit AddedFunds(msg.sender, funds);

This error only occurs when calling addFund. However, if I remove the addFund function, the token does not encounter any errors with buy/sell or transfer operations.

1 Answer 1


Perhaps you are using the function with a value that is too low. Note that in solidity there are no decimals. If you try to store in a unit variable a number that is 1% of 99 (1/99), solidity won't store 0.99, it will store 0.

So, if the amount you are testing with is too low, some of these commissions could be too small, so they end up being rounded to 0.

To mitigate the error, include a condition to only execute safeTransfer if the amount is higher than 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.