Generate an NFT Contract

After creating an NFT collection and adding NFT items to it, you will generate a smart contract for the NFT collection, then deploy it.

To generate the NFT collection smart contract, you need to connect to MetaMask. Then, send a POST request to the /nft/<nft_collection_name> endpoint, calling the :generateContract method.

Generate the contract for an NFT.

POST https://api.playfix.io/nft/<nft_collection_name>:generateContract

Path Parameters

Name
Type
Description

nft_collection_name*

String

Name of the NFT collection. This will start with a prefix of "nfts/" followed by a ULID.

Headers

Name
Type
Description

Authorization*

String

Bearer <your_access_token>

{
  "contract": {
    "source": {
      "main": "//...",
      "imports": {
      @opengsn/contracts/src/BaseRelayRecipient.sol: "..."
      @opengsn/contracts/src/interfaces/IRelayRecipient.sol: "..."
      @openzeppelin/contracts/access/AccessControl.sol: "..."
      @openzeppelin/contracts/access/IAccessControl.sol: "..."
      @openzeppelin/contracts/token/ERC721/ERC721.sol: "..."
      @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol: "..."
      @openzeppelin/contracts/utils/Address.sol: "..."
      @openzeppelin/contracts/utils/Context.sol: "..."
      @openzeppelin/contracts/utils/Strings.sol: "..."
      }
    },
    "abi": "[{...}, {...}, {...}, ...]",
    "bytecode": "0x..."
  }
}

Example Curl API Call

curl --request POST \
  --url https://api.playfix.io/nft/<nft_collection_name>:generateContract \
  --header 'Authorization: Bearer <your_access_token>'

Example Python API Call

import requests

nft = "<nft_collection_name>"

r = requests.post(
    "https://api.playfix.io/nft/" + nft + ":generateContract",
    headers = {
        "Authorization": "Bearer <your_access_token>"
        }
    )

print(r.text)

Response

{
  "contract": {
    "source": {
      "main": "//...",
      "imports": {
      @opengsn/contracts/src/BaseRelayRecipient.sol: "..."
      @opengsn/contracts/src/interfaces/IRelayRecipient.sol: "..."
      @openzeppelin/contracts/access/AccessControl.sol: "..."
      @openzeppelin/contracts/access/IAccessControl.sol: "..."
      @openzeppelin/contracts/token/ERC721/ERC721.sol: "..."
      @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol: "..."
      @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol: "..."
      @openzeppelin/contracts/utils/Address.sol: "..."
      @openzeppelin/contracts/utils/Context.sol: "..."
      @openzeppelin/contracts/utils/Strings.sol: "..."
      }
    },
    "abi": "[{...}, {...}, {...}, ...]",
    "bytecode": "0x..."
  }
}

This sample response is compressed.

Response Fields

  • contract- An object containing the details of the NFT collection smart contract.

    • source- An object containing the source code of the smart contract.

      • main- source code of the main functionalities of the NFT collection contract.

      • imports- imported libraries and dependencies of the smart contract.

    • abi: Method names, parameters and arguments, and data types that can be used to interact with the smart contract.

    • bytecode: The NFT collection contract in low-level binary.

Last updated