Unable to interact with ERC721 tokens deployed on 0.4 solidity contract from 0.5 contract

We deployed a ERC721 token using openzeppelin-solidity 1.9 and 0.4.25 solidity. We are currently writing a new smart contract using solidity 0.5.4. We are using IERC721 interface and interacting with deployed ERC721 contract. We are specifically calling ownerOf and getApproved calls on the token contract. The contract written in 0.5 solidity can interact with a token contract deployed in 0.5. However when we interact with a token contract deployed with 1.9 open zeppelin on solidity 0.4 we get 0x00 for owner and getApproved calls. tokenURI also returns empty string.

Looks like the contract isnt calling the token contract at all. We even wrote an interoperability interface.

pragma solidity >0.4.99 <0.6.0;

interface IERC721 {
    function balanceOf(address owner) external view returns (uint256 balance);
    function ownerOf(uint256 tokenId) external view returns (address owner);
    function safeTransferFrom(address from, address to, uint256 tokenId) external;
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
    function transferFrom(address from, address to, uint256 tokenId) external;
    function approve(address to, uint256 tokenId) external;
    function getApproved(uint256 tokenId) external view returns (address operator);
    function setApprovalForAll(address operator, bool _approved) external;
    function isApprovedForAll(address owner, address operator) external view returns (bool);
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

Any idea what could be wrong here?

1 Like

Hi @yash,

Are you able to share your deployed ERC721 contract address and the code for this contract?


I have deployed an ERC721 (OldNft.sol see code below) to Ropsten (took me a little while to get an 0.4 environment as it has been a while) to reproduce.
I have also verified the code on Etherscan. https://ropsten.etherscan.io/address/0x0f889b567773b3285fabdf1b3d2dc116cc9cbcf4#code
There is a single token, token ID: 1

I created a contract (UseNft.sol see code below) that calls a contract using IERC721 and can call ownerOf.
I tested using truffle console and called on Etherscan read contract UI.
https://ropsten.etherscan.io/address/0x565CD8E77f1a03b770408c1c7543D3389045396E#readContract

OldNft.sol

pragma solidity 0.4.26;

import "openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";

contract OldNft is ERC721Token {
    constructor() public
        ERC721Token("Old NFT", "OLD") {
    }

    function mint(address _to, uint256 _tokenId) public {
        _mint(_to, _tokenId);
    }

    function burn(uint256 _tokenId) public {
        _burn(ownerOf(_tokenId), _tokenId);
    }

    function setTokenURI(uint256 _tokenId, string _uri) public {
        _setTokenURI(_tokenId, _uri);
    }
}

UseNft.sol

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

contract UseNft {

    function ownerOf(IERC721 nft, uint256 tokenId) external view returns (address owner) {
        return nft.ownerOf(tokenId);
    }
}
1 Like

Hi @yash,

Wanted to check how you were getting on with this issue?

Figured out the issue. I need to add the new token contract as approved contract in a registry to make that call. So this is resolved. Appreciate your time @abcoathup.

2 Likes