7
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:

In the Details panel on opensea, I can see the contract schema name as follows: Token Standard: ERC-1155

How can I get schema name from opensea token url using node.js or python?

TylerH
  • 20,799
  • 66
  • 75
  • 101
azvast
  • 337
  • 4
  • 10

1 Answers1

17

According to EIP721, and EIP1155, both of them must implement EIP165. In summary, what EIP165 does is to allow us to check whether the contract implemented the interface or not. Detailed information about https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified

According to EIPs, ERC721 and ERC1155 will implements EIP165. Therefore, we can use the supportsInterface of EIP165 to check whether the contract is ERC721 or ERC1155.

The interface id for ERC1155 is 0xd9b67a26, while the interface of ERC721 is 0x80ac58cd. You can check the EIP165 proposal about how the interface id was calculated.

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.

I found out that OpenSea provide API for you to check it. Here is the link https://docs.opensea.io/reference/retrieving-a-single-contract

TylerH
  • 20,799
  • 66
  • 75
  • 101
kampung-tech
  • 386
  • 1
  • 6