Detecting erc721 contract address across networks?

Hi,

In our contract we have the need to detect if a contract address is in fact an erc721 contract address. To perform this we have the following in our contract:

/**
 * notice Queries a deployed contract to check if it supports known ERC721 interfaces
 * dev Supports the interface ID of the crypto kitties contract
 * param _contract Address of the contract being queried
 */
function _assertContractSupportsERC721Interface(address _contract) private view {
    try IERC721(_contract).supportsInterface(_INTERFACE_ID_ERC721) returns (bool mainResult) {
        // We might be dealing with the CryptoKitties contract if result is false
        if (mainResult == false) {
            try IERC721(_contract).supportsInterface(_INTERFACE_ID_ERC721_CryptoKitties) returns (bool result) {
                require(result == true, "Contract does not implement the ERC721 interface");
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("Invalid NFT contract");
            }
        }
    } catch Error(string memory reason) {
        revert(reason);
    } catch {
        revert("Invalid NFT contract");
    }
}

This function works fine when the target contract address is on the same network the contract is running on (eg. detecting contract and target contract both running on Rinkeby) -- however, if we pass in a contract address running on a different network it fails with the error message "Transaction reverted: function call to a non-contract account"

The question is, is there a way to verify a contract address across networks? for example, detecting contract running on Polygon, target contract running on Mainnet?

Thanks in advance

You should use ERC165Checker instead of calling the contract directly.

There is probably no way to perform this check cross-chain. If there is, it’s going to be very convoluted and possibly not worth the effort.