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 = {
collection:
| HolographLegacyCollection // NFT class usage
| HolographMoeERC721DropV2; // MoeNFT class usage

metadata: {
name: string;
description: string;
creator: string;
attributes?: Record<string, string>;
};

ipfsInfo: {
ipfsImageCid: string;
ipfsMetadataCid: string;
ipfsUrl?: string;
};

version?: HolographVersion;
};

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

import { holographConfig } from "./config";

const myContract = new HolographLegacyCollection(holographConfig, {
primaryChainId: networks.polygon.chain,
collectionInfo: {
name: "My First Collection",
symbol: "MFC",
description: "Probably nothing.",
royaltiesBps: 2000, // 20%
salt: "0x0000000000000000000000000000000000000000000000000000018e7cc167e2",
},
});

const myNFT = new NFT({
collection: myContract,
metadata: {
name: "My new NFT",
description: "Probably nothing.",
creator: "Holograph Protocol",
},
ipfsInfo: {
ipfsImageCid: "QmfPiMDcWQNPmJpZ1MKicVQzoo42Jgb2fYFH7PemhXkM32",
ipfsMetadataCid:
"QmfPiMDcWQNPmJpZ1MKicVQzoo42Jgb2fYFH7PemhXkM32/metadata.json",
},
});
  • Validation:
    • collection:
      HolographLegacyCollection | HolographMoeERC721DropV2required
      - must be a valid instance of the contract class. HolographLegacyCollection is utilized in conjunction with the NFT class, whereas HolographMoeERC721DropV2 is utilized with the MoeNFT class.
    • metadata:
      • name:
        stringrequired
      • description:
        stringrequired
      • creator:
        stringrequired
      • attributes:
        Record<string, string>
    • ipfsInfo:
      • ipfsImageCid:
        stringrequired
      • ipfsMetadataCid:
        stringrequired
      • ipfsUrl:
        stringdefault: ""
    • version:
      HolographVersiondefault: V2

  • Setters:

    NFT class has a couple of setters and they need to follow the above validation. Here's the full list:

    • setName()
    • setDescription()
    • setCreator()
    • setAttributes()
    • setIpfsImageCid()
    • setIpfsMetadataCid()
    • setIpfsUrl()

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


2. Properties

collection

  • Type:
    HolographLegacyCollection | HolographMoeERC721DropV2

The NFT contract data. It is an instance of either HolographLegacyCollection or HolographMoeERC721DropV2.

name

  • Type:
    string

The name of the NFT.

description

  • Type:
    string

The description of the NFT.

creator

  • Type:
    string

The creator name of the NFT.

attributes

  • Type:
    Record<string, string>

The attributes/traits of the NFT.

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.

ipfsImageCid

  • Type:
    string

The IPFS image CID of the NFT. It's a 46-character.

ipfsMetadataCid

  • Type:
    string

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

ipfsUrl

  • Type:
    string

The IPFS file URL of the NFT.

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 MOE NFTs with MoeNFT 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";

import { holographConfig } from "./config";

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

const anotherWallet = new HolographWallet({
account: anotherAccount,
chainsRpc: holographConfig.networks,
});

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

hydrateFrom()
static

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

Params:

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

Returns:

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

HydrateNFTConfig type reference:

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

Example:

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

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

console.log(myNFT.name); // My new NFT
console.log(myNFT.description); // Probably nothing.
console.log(myNFT.creator); // Holograph Protocol

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. MoeNFT

  • Inherits all properties and methods from the NFT class.
  • Is designed for minting only MOE NFTs.
  • Requires the collection constructor parameter to be an instance of HolographMoeERC721DropV2.
  • Allows passing the quantity parameter inside the MintConfig.

Minting a Multichain Open Edition (MOE):

src/holograph/moe-nft.ts
import { HolographMoeERC721DropV2, MoeNFT } from "@holographxyz/sdk";
import { networks } from "@holographxyz/networks";

import { holographConfig. wallet } from "./config";

const myMoeCollection = new HolographMoeERC721DropV2(holographConfig, {
collectionInfo: {
name: "NFTs Without Boundaries",
description: "Possibly the most innovative NFT collection yet.",
symbol: "HOLO",
royaltiesBps: 2000, // 20%
salt: "0x0000000000000000000000000000000000000000000000000000018e7cc167e2",
},
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 myMoeCollection.signDeploy(wallet);

const { collectionAddress } = await myMoeCollection.deploy(
signatureData
);

const myMoeNFT = new MoeNFT({
collection: myMoeCollection,
metadata: {
name: "My new MOE",
description: "Probably nothing.",
creator: "Holograph Protocol",
},
ipfsInfo: {
ipfsImageCid: "QmfPiMDcWQNPmJpZ1MKicVQzoo42Jgb2fYFH7PemhXkM32",
ipfsMetadataCid:
"QmfPiMDcWQNPmJpZ1MKicVQzoo42Jgb2fYFH7PemhXkM32/metadata.json",
},
});

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