Trying to use _transfer inside an OpenZep implementation

I wrote a contract that extends OpenZep’s ERC20PresetFixedSupply contract. My goal is to add a function that sends tokens to a hardcoded address. I tried to add this function transferToVitalik but it is not working:

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.4;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.1.0/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol";

contract TESTToken is ERC20PresetFixedSupply("TestCoin", "TEST", 10**24, msg.sender) {
    function transferToVitalik() public {
        _transfer(msg.sender, address(0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B), uint256(500000000000000000000000));
    }
}

I deployed via Remix and tried to use the function, but Metamask pops up to do the transaction and the value is 0.

I am confused on why this does not work cause I am just wrapping the _transfer method and hardcoding the arguments. I tried also wrapped transfer and transferFrom instead and I get the same behavior.

The “value” of 0 corresponds to the amount of ETH sent in the transaction. Tokens do not count as value in this sense.

But if I interact with the native transfer method, it won’t show 0 in metamask, it will instead correctly reflect the tokens I want to send.

Ok sorry I wasn’t familiar with that.

In that case, it must be recognizing the standard transfer(address,uint) function signature and showing the uint argument as the value. I doubt Metamask is simulating the transaction to detect that internally a transfer will be performed.

So if you want Metamask to display the value you have to use ERC20’s built in transfer function.

I tried both _transfer and transfer and I get the same result. Metamask just shows 0 and if I do the transaction, it indeed does not send anything.

You could try by just pasting that code snippet into remix.

Ok retried it. It actually does work if I use transfer within my transferToVitalik function. It actually sends the tokens, but it still does not show in Metamask. Is this some limitation of Metamask?

Yeah looks like Metamask will only show the value if the function name is transfer or transferFrom