简体   繁体   English

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

[英]How to check if the token on opensea is ERC721 or ERC1155 using node.js

const { OpenSeaPort, Network } = require("opensea-js");

const offer = await seaport.createBuyOrder({
      asset: {
        tokenId,
        tokenAddress,
        schemaName
      },
      accountAddress: WALLET_ADDRESS,
      startAmount: newOffer / (10 ** 18),
      expirationTime: Math.round(Date.now() / 1000 + 60 * 60 * 24)
    });

I am going to get schemaName (if ERC721 or ERC1155) from opensea empty token:我将从 opensea 空令牌中获取schemaName (如果是 ERC721 或 ERC1155):

In the Details panel on opensea, I can see the contract schema name as follows: Token Standard: ERC-1155在opensea的Details面板中,可以看到合约模式名称如下: Token Standard: ERC-1155

How can I get schema name from opensea token url using node.js or python?如何使用 node.js 或 python 从 opensea 令牌 url 获取模式名称?

I have been following the question for a good answer.我一直在关注这个问题以获得一个好的答案。 However, seems like no one is answering.然而,似乎没有人回答。 Therefore, I'm giving my own solution.因此,我给出了自己的解决方案。

According to EIP721, and EIP1155, both of them must implement EIP165.根据 EIP721 和 EIP1155,它们都必须实现 EIP165。 In summary, what EIP165 does is to allow us to check whether the contract implemented the interface or not.综上所述,EIP165 所做的就是让我们检查合约是否实现了接口。 Detailed information about https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified有关https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified 的详细信息

According to EIPs, ERC721 and ERC1155 will implements EIP165.根据 EIP,ERC721 和 ERC1155 将实施 EIP165。 Therefore, we can use the supportsInterface of EIP165 to check whether the contract is ERC721 or ERC1155.因此,我们可以使用supportsInterface的EIP165检查合同是否是ERC721或ERC1155。

The interface id for ERC1155 is 0xd9b67a26 , while the interface of ERC721 is 0x80ac58cd . ERC1155 的接口 id 是0xd9b67a26 ,而0xd9b67a26的接口是0x80ac58cd You can check the EIP165 proposal about how the interface id was calculated.您可以查看有关如何计算接口 ID 的 EIP165 提案。

The below is the code example.下面是代码示例。

import Web3 from "web3";
import dotenv from "dotenv";
dotenv.config();
var web3 = new Web3(
  new Web3.providers.HttpProvider(process.env.RINKEBY_URL || "")
);

const ERC165Abi: any = [
  {
    inputs: [
      {
        internalType: "bytes4",
        name: "interfaceId",
        type: "bytes4",
      },
    ],
    name: "supportsInterface",
    outputs: [
      {
        internalType: "bool",
        name: "",
        type: "bool",
      },
    ],
    stateMutability: "view",
    type: "function",
  },
];

const ERC1155InterfaceId: string = "0xd9b67a26";
const ERC721InterfaceId: string = "0x80ac58cd";
const openSeaErc1155Contract: string =
  "0x88b48f654c30e99bc2e4a1559b4dcf1ad93fa656";
const myErc721Contract: string = "0xb43d4526b7133464abb970029f94f0c3f313b505";

const openSeaContract = new web3.eth.Contract(
  ERC165Abi,
  openSeaErc1155Contract
);
openSeaContract.methods
  .supportsInterface(ERC1155InterfaceId)
  .call()
  .then((res: any) => {
    console.log("Is Opensea", openSeaErc1155Contract, " ERC1155 - ", res);
  });

openSeaContract.methods
  .supportsInterface(ERC721InterfaceId)
  .call()
  .then((res: any) => {
    console.log("Is Opensea", openSeaErc1155Contract, " ERC721 - ", res);
  });

const myContract = new web3.eth.Contract(ERC165Abi, myErc721Contract);
myContract.methods
  .supportsInterface(ERC1155InterfaceId)
  .call()
  .then((res: any) => {
    console.log("Is MyContract", myErc721Contract, " ERC1155 - ", res);
  });

myContract.methods
  .supportsInterface(ERC721InterfaceId)
  .call()
  .then((res: any) => {
    console.log("Is MyContract", myErc721Contract, " ERC721 - ", res);
  });

The solution above need to connect to an Ethereum node such as infura in order to works.上述解决方案需要连接到Ethereum node例如 infura 才能工作。

Please enlighten me if there is a better solution.如果有更好的解决方案,请赐教。

Thanks.谢谢。

Edit: I found out that OpenSea provide API for you to check it.编辑:我发现 OpenSea 提供 API 供您检查。 Here is the link https://docs.opensea.io/reference/retrieving-a-single-contract这是链接https://docs.opensea.io/reference/retrieving-a-single-contract

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

相关问题 如何使用 web3 Python 转移 ERC1155 令牌? - How to transfer ERC1155 token using web3 Python? 使用 Python/Web3.py 传输 ERC721 令牌 - Transferring ERC721 Tokens using Python/Web3.py 如何获取某个地址的某些 ERC721 代币的 tokenid? 使用 Web3py - How to get the tokenids of certain ERC721 tokens for a adress? using Web3py 来自 web3 的 MintTo 合同给出错误 - ERC721:转移到非 ERC721Receiver 实施者 - MintTo contract from web3 gives error - ERC721: transfer to non ERC721Receiver implementer 如何使用 Web3py 获取特定合约的 ERC20 代币交易 - How to get ERC20 Token Transaction of a specific contract using Web3py 使用本地私钥向web3.py发送ERC20令牌 - Send ERC20 token with web3.py using a local private key 如何使用 web3.py 在钱包之间转移 ERC20 代币 - How to transfer an ERC20 token between wallets with web3.py 从 ERC-20 代币地址获取有关代币的详细信息 - Obtaining details about a token from an ERC-20 token address 在给定的时间戳获取所有持有 ERC20 代币的地址 - Fetch all addresses holding an ERC20 token at a given timestamp 在默认本地 ganache 上部署时,Brownie ParserError openzeppelin/contracts/token/ERC20/ERC20.sol - Brownie ParserError openzeppelin/contracts/token/ERC20/ERC20.sol when deploying on default local ganache
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM