0

I am experimenting with OpenZepplin Hooks to modify ERC20 transfer functions in this way

contract IToken is ERC20 { 
....
function _beforeTokenTransfer(address from, address to, uint256 amount)
    internal virtual override
{
    super._beforeTokenTransfer(from, to, amount);

    require(amount > 1, "ERC20: invalid transfer amount");
}

}

However if set amount = 0.5 tokens the transfer is still happening. Any idea what is the right way to make transfer fail if the condition is not met?

3
  • 1
    What is the decimal do you token! There is not such a thing as 0.5 token, solidity has no floating number. In normal erc20 1 does not mean 1 token, the tools like metamask just show you “1” based on the decimal of the erc20 so if you have 1 token then the amount is actually not 1 in the smart contract it is 100000.......etc.
    – Majd TL
    May 5 at 13:19
  • of* your* token!
    – Majd TL
    May 5 at 13:30
  • @MajdTL Realized that was the problem. Thanks May 5 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.