OpenZeppelin/openzeppelin-contracts

Enable override on safeTransferFrom

saingsab opened this issue ยท 2 comments

๐Ÿง Motivation
Want to have a similar Souldbon token but with some condition, let's say in the future the token can be transfer but only form the admin or OP role based.

๐Ÿ“ Details

this is the default safeTransferFrom

function safeTransferFrom(address from, address to, uint256 tokenId) public {

after add virtual then we can override.
I am not sure if this is the best approach,

below implement no longer work:

function _beforeTokenTransfer(address from, address to, uint256 tokenId)
        internal
        override
    {
        require(from == address(0), "Token not transferable");
        super._beforeTokenTransfer(from, to, tokenId);
    }

Hi @saingsab,

Hooks were removed in 5.0, so _beforeToken* won't work anymore. Instead, we recommend overriding the _update function, which is the core of any token transfer within the contract and is virtual.

I'd suggest doing:

function _update(address to, uint256 tokenId, address auth)
        internal
        override
    {
        require(from == address(0), "Token not transferable");
        super._update(to, tokenId, auth);
    }

Wonderful, just had an update and it's working good!