In openzeppelin contracts in same cases we have 2 types of functions for the same functionality, one of them preceded by a dash symbol (_). That is the case of transfer(x, y, z)/_transfer(x, y, z) function.

I am aware that when I want to modify the behaviour if I inherit the function, I should use _transfer(x, y, z).

But what's the real difference? Because it happens in lot of functions, and I'm not really sure if I should use transfer(x, y, z) or _transfer(x, y, z).

So then, if I'm not gonna modify its original behaviour, should I use transfer or _transfer?

Thanks in advance

2 Answers 2


The reason for function _transfer is simply code-reuse.

It is called from both functions transfer and transferFrom.

It can also be called from functions mint and burn, if you need to implement them.

And when the exact same functionality is used in several places, it is beneficial to implement it in a single place rather than in several places, because:

  1. It allows you to to fix/change/update the common functionality in a single place
  2. The overall size of your executable (binary) code is subsequently smaller
  • So then, if I'm not gonna modify its original behaviour, should I use transfer or _transfer?Thanks Dec 19, 2020 at 9:37
  • 1
    @AlexAcc: What do you mean "use"? From other contracts (as well as from the off-chain), you cannot "use" _transfer since it's internal. So define "use" please. Dec 19, 2020 at 9:40
  • Ok sorry, I didn't get the point that _transfer is internal (for only to use inside the contract). So if I need to make a transfer inside of the contract logic I should use _transfer, and if I need to invoke a transfer outside the contract I'd use transfer. Right? Dec 19, 2020 at 9:58
  • 1
    @AlexAcc: Outside - transfer of course. Inside - depending on your exact purpose, but most likely _transfer. Dec 19, 2020 at 10:36

Imagine, you have a frontend for your smart contract. From frontend, you cannot call _mint or _approve. They are internal. They can be can be called inside the functions of your smart contracts.


    function mintTokens() external {
        _mint(msg.sender, 10*10**18);


await window.contract.methods.mintTokens().send({from: account});

From index.html mintTokens() is called, not _mint

Your Answer

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

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