如何修复“身份不明的合同”? OpenSea 无法“理解”ERC1155

Posted

技术标签:

【中文标题】如何修复“身份不明的合同”? OpenSea 无法“理解”ERC1155【英文标题】:How to fix "Unidentified contract"? OpenSea is unable to “understand” ERC1155 【发布时间】:2021-10-23 17:14:02 【问题描述】:

我已经部署了一个基于 ERC-1155 的合约(基于 OpenZeppelin)并成功地在该合约上铸造了一些 NFT。但是当我想在 OpenSea 中使用这些 NFT 时,它总是说 “Unidentified contract”

示例:https://testnets.opensea.io/assets/0xc7d3e4a5A0c3e14ba8C68ea1b8a99a9dBf3ca76F/2

API 示例:https://testnets-api.opensea.io/api/v1/asset/0xc7d3e4a5A0c3e14ba8C68ea1b8a99a9dBf3ca76F/2/?force_update=true

按照他们的official Tutorial repository(由于过时的依赖项和其他问题不再编译),我添加了一些(可能)OpenSea 特定的函数和数据,OpenSea 可能需要这些函数和数据才能正常工作。然而,OpenSea 能够抓取所有需要的数据来显示 NFT,但只要他们说“未识别的合约”,到目前为止这一切都没有意义。

我的问题是:

是否有人已经设法部署 ERC-1155 并将其与 OpenSea 一起正确使用而没有出现此问题?有什么我们必须以某种方式“注册”不基于 ERC-721 的合约吗?

????代码重现

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";


contract OwnableDelegateProxy  

contract ProxyRegistry 
  mapping(address => OwnableDelegateProxy) public proxies;



contract MetaCoin is ERC1155, AccessControl, Pausable, ERC1155Burnable 
    bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

    address proxyRegistryAddress;


    constructor(address _proxyRegistryAddress) ERC1155("https://abcoathup.github.io/SampleERC1155/api/token/id.json")        
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(URI_SETTER_ROLE, msg.sender);
        _setupRole(PAUSER_ROLE, msg.sender);
        _setupRole(MINTER_ROLE, msg.sender);

        proxyRegistryAddress = _proxyRegistryAddress;
    

    function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) 
        _setURI(newuri);
    

function pause() public onlyRole(PAUSER_ROLE) 
    _pause();


function unpause() public onlyRole(PAUSER_ROLE) 
    _unpause();


function supportsInterface(bytes4 interfaceId)
    public
    view
    override(ERC1155, AccessControl)
    returns (bool)

    return super.supportsInterface(interfaceId);


    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyRole(MINTER_ROLE)
    
        _mint(account, id, amount, data);
    

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyRole(MINTER_ROLE)
    
        _mintBatch(to, ids, amounts, data);
    

    function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        internal
        whenNotPaused
        override
    
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
    

  /**
   * Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
   */
  function isApprovedForAll(
    address _owner,
    address _operator
  ) public override view returns (bool isOperator) 
    // Whitelist OpenSea proxy contract for easy trading.
    ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
    if (address(proxyRegistry.proxies(_owner)) == _operator) 
      return true;
    

    return ERC1155.isApprovedForAll(_owner, _operator);
  



????环境

节点:v16.7.0

部门:

"@openzeppelin/contracts": "^4.3.0",
"@nomiclabs/buidler": "^1.4.8",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/hardhat-upgrades": "^1.9.0",
"@typechain/ethers-v5": "^6.0.5",
"@typechain/hardhat": "^1.0.1",
"@types/chai": "^4.2.15",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"chai": "^4.3.3",
"chai-as-promised": "^7.1.1",
"chai-datetime": "^1.8.0",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.4.5",
"hardhat": "^2.6.1",
"hardhat-typechain": "^0.3.5",
"ts-generator": "^0.1.1",
"ts-node": "^9.1.1",
"typechain": "^4.0.3",
"typescript": "^4.2.4"

【问题讨论】:

【参考方案1】:

我终于找到了根本原因! OpenSea 需要一个名为 name 的公共属性来显示集合的正确名称,而不是静态标签未识别的合同

我在查看他们的 reference code 时遇到了这个问题(这取决于现在 3 岁的 MultiToken-Contract implementation 并且需要对 Node 和其他工具进行一些降级才能构建它[降级到节点 10 今天最适合我])。

【讨论】:

我已按照本教程进行批量上传:youtu.be/VglTdr0n5ZQ?t=1496。图片在测试网上,但它们的顶部都有Unidentified contract - DmXmQaXXXX!知道如何解决吗?顺便问一下,您知道我们是否可以将文件夹上传到我们在 OpenSea 上拥有的现有集合中?

以上是关于如何修复“身份不明的合同”? OpenSea 无法“理解”ERC1155的主要内容,如果未能解决你的问题,请参考以下文章

通过 JS API 在 OpenSea 上列出 NFT:无法提取 transfer calldata 错误 400

使用 Opensea API 检索订单让我无法通过 Cloudflare

如何创建像 OpenSea 这样的签名交易

钓鱼攻击威胁NFT资产安全

以太坊如何发布NFT到opensea

如何使用 node.js 检查 opensea 上的令牌是 ERC721 还是 ERC1155