简体   繁体   English

阻止 OpenSea 交易

[英]Block OpenSea trading

Is there a way to avoid trading NFTs on standard marketplaces like OpenSea without breaking the erc721 standard?有没有办法在不破坏 erc721 标准的情况下避免在 OpenSea 等标准市场上交易 NFT? If so, how would you go about it?如果是这样,你会怎么go一下呢? It is about an NFT that is something like a voucher that can be used 5 times.它是关于一种 NFT,类似于可以使用 5 次的代金券。 Over 5 years, once per year. 5年以上,每年一次。 I would like to prevent that someone unknowingly buys a redeemed voucher (for the current year).我想防止有人在不知不觉中购买兑换券(当年)。

You can include checks in your transfer function.您可以在转账 function 中包含支票。

Keep a global map counter with token IDs pointing to the number of transactions per token保留一个全局 map 计数器,其代币 ID 指向每个代币的交易数量

mapping(uint256=> uint256) private _tokenTx;

Now, in your transfer function you can use the NFT id, check in the map to see if it's lower than 5, if it is, you fail the tx, otherwise you continue and increase the number现在,在您的转账 function 中,您可以使用 NFT id,检查 map 以查看它是否低于 5,如果是,则交易失败,否则继续并增加数量

    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
        require(to != address(0), "ERC721: transfer to the zero address");
        **require(_tokenTx[tokenId] <6, "ERC721: can\'t transfer more than 5 times");**

        _approve(address(0), tokenId);

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        **_tokenTx[tokenId] = _tokenTx[tokenId]+1;**

        emit Transfer(from, to, tokenId);

    }

As for filtering exchanges transfers, you can either keep a dynamic list with the addresses they use, or block the approval processes altogether.至于过滤交易所转账,您可以保留一个包含他们使用的地址的动态列表,或者完全阻止批准过程。 The first keeps the standard better but is harder and more expensive to keep up, the second one is a bit more aggressive but will work for all popular exchanges out there第一个更好地保持了标准,但跟上它更难且成本更高,第二个更激进但适用于所有流行的交易所

Or, if you're using an external link to redirect buyers/traders to the text file that lists the voucher code, all you have to do is replace the voucher code(s) with a message saying that all the vouchers have been redeemed and then save the file.或者,如果您使用外部链接将买家/交易者重定向到列出优惠券代码的文本文件,您所要做的就是用一条消息替换优惠券代码,说明所有优惠券都已兑换,并且然后保存文件。 That way, the next time the NFT gets traded and they unlock the link, they'll see the message.这样,下次 NFT 交易并解锁链接时,他们就会看到消息。

I sure as hell ain't going to waste my time trying to figure out all that coding nonesense...lol.我绝对不会浪费我的时间试图弄清楚所有这些无意义的编码...大声笑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM