Skip to main content

NFT

The NFT class oversees NFTs generated from a holographable contract, offering functionality for minting NFTs.

1. Constructor Parameters

createNFTInput

  • Type:
    CreateNFTrequired

The input object to enable the NFT settings and mints.

type CreateNFT = {
contract:
| HolographERC721Contract // NFT class usage.
| HolographOpenEditionERC721ContractV2; // OpenEditionNFT class usage.
ipfsMetadataCid: string;
version?: HolographVersion;
};

enum HolographVersion {
V1 = "V1",
V2 = "V2",
}
src/holograph/nft.ts
import { HolographERC721Contract, NFT } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

const myContract = new HolographERC721Contract({
primaryChainId: networks.polygon.chain,
contractInfo: {
name: "My First Contract",
symbol: "MFC",
royaltiesPercentage: 2000, // 20%.
},
});

const myNFT = new NFT({
contract: myContract,
ipfsMetadataCid: "QmfPiMDcWQNPmJpZ1MKicVQzoo42Jgb2fYFH7PemhXkM32/metadata.json",
});
  • Validation:
    • contract:
      HolographERC721Contract | HolographOpenEditionERC721ContractV2required
      - must be a valid instance of the contract class. HolographERC721Contract is utilized in conjunction with the NFT class, whereas HolographOpenEditionERC721ContractV2 is utilized with the OpenEditionNFT class.
    • ipfsMetadataCid:
      stringrequired
      - must be a valid IPFS metadata CID, ending with metadata.json. It's only required for the NFT class, you don't need to pass it for the OpenEditionNFT class.
    • version:
      HolographVersiondefault: V2

  • Setters:
    • setIpfsMetadataCid() - Sets the IPFS metadata CID for the NFT. It must end with metadata.json.

⚠️ The NFT must be minted before the setters can be envoked.


2. Properties

contract

  • Type:
    HolographERC721Contract | HolographOpenEditionERC721ContractV2

The NFT contract data. For the NFT class, it is an instance of the HolographERC721Contract class. For the OpenEditionNFT class, it is an instance of HolographOpenEditionERC721ContractV2 class.

ipfsMetadataCid

  • Type:
    string

The IPFS metadata CID file of the NFT. It is usually the IPFS image CID with the metadata.json suffix.

isMinted

  • Type:
    boolean

A boolean to indicate whether the NFT is minted or not.

tokenId

  • Type:
    string

The token ID of the minted NFT. It gets automatically populated after invoking the mint function successfully.

txHash

  • Type:
    0x${string}

The transaction hash of the last mint.


3. Methods

mint()

Mints an NFT created by an holographable contract.

Params:

  • mintConfig:
    MintConfigrequired
  • options:
    WriteContractOptionsdefault: {}
    - The option overrides object for the transaction.

Returns:

Promise<{ tokenId: 0x{string}, txHash: 0x{string} }>

MintConfig type reference:

import { HolographWallet } from "@holographxyz/sdk";

type MintConfig = {
chainId: number;
quantity?: number; // Used only for minting open edition NFTs with OpenEditionNFT class.
wallet?: { account: string | HolographWallet };
};

Example:

import { networks } from "@holographxyz/networks";

const { tokenId, txHash } = await myNFT.mint({
chainId: networks.polygon.chain,
});

How to override the default options:

import { HolographAccountFactory, HolographWallet } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

const anotherAccount = HolographAccountFactory.createAccountUsingPrivateKey(
process.env.ANOTHER_PRIVATE_KEY
);

const anotherWallet = new HolographWallet({
account: anotherAccount,
});

const { tokenId, txHash } = await myNFT.mint(
{
chainId: networks.polygon.chain,
wallet: anotherWallet,
},
{
options: {
gasLimit: BigInt(1000),
},
}
);

hydrate()
static

Hydrates the NFT from its token ID, contract address and chain ID.

Params:

  • hydrateNFT:
    HydrateNFTConfigrequired
    - The configuration object for hydrating the NFT. See below for the type reference.

Returns:

Promise<NFT | OpenEditionNFT>
- The hydrated NFT class instance, ready for use.

HydrateNFTConfig type reference:

type HydrateNFTConfig = {
chainId: number;
contractAddress: 0x${string};
tokenId: string;
}

Example:

import { NFT } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

// NFT class instance:
const myNFT = await NFT.hydrateFrom({
chainId: networks.polygon.chain,
contractAddress: "0xaaaB48817189C5768887Ed7809ebF6E88e629bD5",
tokenId: "0x0000000000000000000000000000000000000000000000000000000000000001",
});

tokenIdExists()

Verifies the existence of a token ID.

Params:

  • tokenId:
    stringrequired
  • chainId:
    numberrequired

Returns:

Promise<boolean>

import { networks } from "@holographxyz/networks";

const exists = await myNFT.tokenIdExists(
"0x0000000000000000000000000000000000000000000000000000000000000001",
networks.polygon.chain
);

getOwner()

Gets the NFT owner address.

Params:

  • tokenId:
    stringrequired
  • chainId:
    numberrequired

Returns:

Promise<`0x${string}`>

import { networks } from "@holographxyz/networks";

const owner = await myNFT.getOwner(
"0x0000000000000000000000000000000000000000000000000000000000000001",
networks.polygon.chain
);

isOwner()

Validates whether an address is the rightful owner of the NFT.

Params:

  • account:
    0x${string}required
  • tokenId:
    stringrequired
  • chainId:
    numberrequired

Returns:

Promise<boolean>

import { networks } from "@holographxyz/networks";

const isOwner = await myNFT.isOwner(
"0xF1B85f7629B8B6C07cA3c318b5629671b5427E8F",
"0x0000000000000000000000000000000000000000000000000000000000000001",
networks.polygon.chain
);

getParsedTokenId()

Gets the parsed version of the minted NFT token ID.

Returns:

ParsedTokenId

ParsedTokenId type reference:

type ParsedTokenId = {
decimal: string;
hex: 0x${string};
part: {
chainId: string;
tokenNumber: string;
};
};
const parsedTokenId = await myNFT.getParsedTokenId();

4. OpenEditionNFT

  • It's a class designed for minting/purchasing open edition NFTs.
  • The contract constructor parameter must be an instance of either HolographOpenEditionERC721ContractV2 or HolographOpenEditionERC721ContractV1. You don't need to pass the ipfsMetadataCid constructor parameter.
  • It has all properties and methods from the NFT class, except for the ipfsMetadataCid property and the setIpfsMetadataCid() setter. Besides that, it includes a new method purchase(), which is pretty much a copy of the mint() method, but with the quantity parameter added.

Purchasing a Multichain Open Edition (MOE):

src/holograph/open-edition-nft.ts
import {
HolographOpenEditionERC721ContractV2,
HolographVersion,
OpenEditionNFT,
} from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

import { wallet } from "./config";

const myOpenEditionContract = new HolographOpenEditionERC721ContractV2({
contractInfo: {
name: "NFTs Without Boundaries",
description: "Possibly the most innovative NFT contract yet.",
symbol: "HOLO",
royaltiesPercentage: 2000, // 20%.
},
nftInfo: {
ipfsImageCid: "QmQJNvXvNqfDAV4srQ8dRr8s4FYBKB67RnWhvWLvE72osu",
ipfsUrl: "ipfs://fileurl.com/file",
},
salesConfig: {
maxSalePurchasePerAddress: 10,
publicSaleStart: "2025-01-01T00:00:00Z",
publicSaleEnd: "2025-01-07T00:00:00Z",
publicSalePrice: 25, // USD unit.
},
primaryChainId: networks.polygon.chain,
});

const signatureData = await myOpenEditionContract.signDeploy(wallet);
const { contractAddress } = await myOpenEditionContract.deploy(signatureData);

const myOpenEditionNFT = new OpenEditionNFT({
contract: myOpenEditionContract,
});

const { tokenId, txHash } = await myOpenEditionNFT.purchase({ // Calling myOpenEditionNFT.mint() also works.
chainId: networks.polygon.chain,
quantity: 10,
});

5. Retrieving NFT Data

You can retrieve data from a minted NFT using the following approach:

src/holograph/nft.ts
import { ContractType, HolographProtocol } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

import { wallet } from "./config";

const protocol = new HolographProtocol();

// NFT class instance:
const nft = await protocol.hydrateNFT({
contractAddress: "0xaaaB48817189C5768887Ed7809ebF6E88e629cf8",
chainId: networks.polygon.chain,
type: ContractType.CxipERC721,
tokenId: "0x0000000000000000000000000000000000000000000000000000000000000001",
});

// OpenEditionNFT class instance:
const openEditionNFT = await protocol.hydrateNFT({
contractAddress: "0xbBbB48817189C5768887Ed7809ebF6E88e629d58",
chainId: networks.polygon.chain,
type: ContractType.HolographOpenEditionERC721V2,
tokenId: "0x0000000000000000000000000000000000000000000000000000000000000001",
});