ERC721 safeTransferFrom doesn't error when transferred to a contract not implementing IERC721Receiver

Hi,

continuing the above query I only get the issue while testing on testnet why is that ?

1 Like

Hi @viraj124,

I am sorry you had this issue. Unfortunately, I wasn’t able to reproduce using the following simple example.

GameItem.sol

// contracts/GameItem.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract GameItem is ERC721 {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() public ERC721("GameItem", "ITM") {}

    function awardItem(address player, string memory tokenURI)
        public
        returns (uint256)
    {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(player, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}

MyContract.sol

// contracts/MyContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract MyContract {
}

Manual Test

I tested manually using truffle develop

truffle(develop)> gameItem = await GameItem.new()
undefined
truffle(develop)> myContract = await MyContract.new()
undefined
truffle(develop)> await gameItem.awardItem(accounts[0], "https://example.com/token/1")
{ tx:
   '0x29c26a427e6cdfe3f1c44dee74c39b15892f38c37fe145f1ad919f840adbecd0',
...
truffle(develop)> await gameItem.ownerOf(1)
'0x0445c33BdCe670D57189158b88c0034B579f37cE'
truffle(develop)> await gameItem.safeTransferFrom(accounts[0], myContract.address, 1)
Thrown:
{ Error: Returned error: VM Exception while processing transaction: revert ERC721: transfer to non ERC721Receiver implementer -- Reason given: ERC721: transfer to non ERC721Receiver implementer.

Hi @viraj124,

Are you still getting this issue?

resolved now, some issue on the contract side

1 Like