简体   繁体   English

我正在创建一个智能合约来与特定的 NFT 进行交互。 有没有function来过滤具体的NFT合约地址?

[英]I'm creating a smart contract to interact with specific NFTs. Is there a function to filter a specific NFT contract address?

I wanted to create a smart contract that only interacts with a specific NFT.我想创建一个只与特定 NFT 交互的智能合约。 I know there is a "tokenID" attribute I don't think this is unique.我知道有一个“tokenID”属性,我认为这不是唯一的。 Cronoscan shows multiple collections that have the same tokenIDs. Cronoscan 显示多个具有相同 tokenID 的 collections。 Does anyone know if smart contracts can filter based on a contract address?有谁知道智能合约是否可以根据合约地址进行过滤? I'd like to accomplish this with as little gas as possible.我想用尽可能少的气体来完成这个。

Sorry if this is a basic question but I've Googled and searched this message board for the answer but was not able to find on other that someone trying to sell their service.很抱歉,如果这是一个基本问题,但我已经用谷歌搜索并搜索了这个留言板的答案,但无法在其他人试图出售他们的服务的地方找到答案。

I Google and search Stack Overflow but could not find an answer.我谷歌并搜索 Stack Overflow 但找不到答案。

Yes, each contract will have their own set of ids and therefore they are not unique between contracts only unique for each contract.是的,每个合约都有自己的一组 ID,因此它们在合约之间不是唯一的,只是每个合约唯一。

This checks if the code size for the address is > 0. This will have to be implemented on a new contract or you will have to find an existing contract with this functionality to view/execute it这将检查地址的代码大小是否 > 0。这将必须在新合约上实施,或者您必须找到具有此功能的现有合约才能查看/执行它

function isContract(address addressValue) public view returns (bool) {
    uint size;
    assembly { size := extcodesize(addressValue) }
    return size > 0;
}

Also notice this is a view function and for that reason wont cost any gas to execute.另请注意,这是一个视图 function,因此不会花费任何气体来执行。

In regards to someone selling it as a service, you can get it yourself by just deploying this contract on whatever main.net you want (by the sounds of it Cronos).对于将其作为服务出售的人,您可以通过在您想要的任何 main.net 上部署该合约来自己获得它(听起来像 Cronos)。

'// SPDX-License-Identifier: MIT

 pragma solidity 0.8.7;

 contract ContractIdentifier{

      function isContract(address addressValue) public view returns (bool) {
          uint size;
          assembly { size := extcodesize(addressValue) }
          return size > 0;
      }
 }

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

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