Where this _beforeTokenTransfer function come from on erc1155 contract?

I am looking at to erc1155 contract on https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol
I want to make a soulbound nft. As i see i need to use _beforeTokenTransfer function.
But i cant find _beforeTokenTransfer function anywhere? Where is this come from?

:computer: Environment


If Iā€™m not mistaken they removed them in 4.9 in favor of just using _mint, _burn and _update
Not sure what was reasoning behind it but people smarter then me made that decision :smile:

Previously, function _beforeTokenTransfer was called from each one of the following functions:

  • _safeTransferFrom
  • _safeBatchTransferFrom
  • _mint
  • _mintBatch
  • _burn
  • _burnBatch

In the current version, function _update is called from each one of these functions instead.

So you could say that function _beforeTokenTransfer was simply replaced with function _update, though it wouldn't be entirely accurate, since the latter seems to encompass quite a bit of code-reuse.

_beforeTokenTransfer is present in 4.9. If you get your contracts from NPM or from the github releases it will be available.

Note: you shoud NOT use the master branch for your dependency. This is where development happens. It contains unaudited code.

In 5.0 (due to ship in a few weeks-months) the _beforeTokenTransfer and _afterTokenTransfer hooks are removed in favor of directly overloading _update:

function _update(
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
) internal virtual {
    // put the code to run **before** the transfer HERE
    super._update(from, to, ids, amounts, data);
    // put the code to run **after** the transfer HERE