-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning: Unreachable code on _checkOnERC721Received when overriding the transferFrom function. #5153
Comments
Hey @armgit5 I could not find any reference for _checkOnERC721Received in the As far as I remember, this functions requires the target address to implement this function The reason it is reverting when you place And you are right, it should be called, as described, after the transfer event happened. But if the target destination doesn't have such implementation or depending on how you coded yours, it should not do anything. |
Hi @0xneves Thank you so much for your response and clarification. I noticed in the commit above that My goal is to override It makes sense that |
Then you should go for overriding the
Then implement your on |
I’ve tried the suggested approach, but I encountered the following error:
Here’s my current transfer and transferFrom implementation: function transferToken(address to, uint256 tokenId) public payable {
require(ownerOf(tokenId) == _msgSender(), "Caller is not owner");
TokenDetails memory details = _tokenDetails[tokenId];
uint256 fee = (details.price * _transferFeePercentage) / MULTIPLIER;
require(msg.value == fee, "Invalid transfer fee");
_transfer(_msgSender(), to, tokenId);
if (!_transferred[tokenId]) {
_transferred[tokenId] = true;
}
emit TokenTransferred(
_msgSender(),
to,
tokenId,
details.price,
fee,
block.timestamp
);
}
function transferFrom() public override {
revert();
} It seems like I have to specify the signature for the |
I think by just using this it might work:
You can also send me the repo you are working on and I can take a quick look in the entire contract |
I tried the above suggestion, but I’m still getting an |
Hey @armgit5 sorry for the late, I've looked into your repo and it's compiling normally... The warning can be removed by changing the transfer function into a require/if statement and making sure you can only transfer to the zeroth address, all other transfers will be unavailable function transferFrom(
address,
address to,
uint256
) public virtual override(ERC721Upgradeable, IERC721) {
if (to != address(0)) revert("Use transferToken");
} Are you still having the issue? If so, could you describe it better? |
@0xneves No worries at all, and thank you so much for checking into the issue for me. After trying it with require or if statement, the warning disappeared. I really appreciate your help so much 🙏 |
💻 Environment
npx hardhat clean & npx hardhat compile
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2"
},
📝 Details
Note: a minor warning has appeared for the first time after compiling.
I’m using
@openzeppelin/contracts-upgradeable
and trying to override thetransferFrom
function. When I runnpx hardhat clean & npx hardhat compile
, I’m encountering a warning:It appears that _checkOnERC721Received isn’t being called on line 184, but if I swap the order and place _checkOnERC721Received first like the following code block, the warning disappears. I’m curious if _checkOnERC721Received should be called before transferFrom?
🔢 Code to reproduce bug
Here’s my overridden transferFrom function:
Could you help clarify if _checkOnERC721Received should be called before transferFrom to avoid the warning when overriding the function?
The text was updated successfully, but these errors were encountered: