Mint a NFT Token
Deploy your NFT Contract if Not Deployed
To mint a token we assume you've already deployed your NFT contract.
import { ClientFactory, NftTokenBuilder } from "@1o1art/sdk";
// setup the client
const client = ClientFactory.makeClient(PRIVATE_KEY, RPC_URL);
const nftContractBuilder = client.createNftContractBuilder();
const contractFacets = await client.getPresetFacets("delegatable");
const contractAddr = await nftContractBuilder
  .setFacets(contractFacets)
  .setImage("ipfs://QmNoDT3M1FfF7d3Pd9DkBfzz8NxHueeudWBPe9owt1PnRM", "offchain")
  .setMetadata({
    name: "My NFT",
    description: "This is my NFT",
    symbol: "FIRST",
  })
  .deploy();
Create your a TokenBuilder
The token builder allows you to reference your deployed NFT contract to mint tokens
import { NftTokenBuilder } from "@1o1art/sdk";
// Prepare to create a token
const nftTokenBuilder = new NftTokenBuilder(
  nftContractBuilder.signer,
  contractAddr
);
Set the token metadata
We use the builder to set metadata, images, and animation for tokens that are minted for the NFT Contract.
The metadata consists of name, desc . The animation and images are also set via the builder. Attributes are translated into an
Opensea compatible attributes trait_type format and the images and animation can be onchain or offchain. If it's offchain then
the expectation is that it's ipfs://, if it's onchain, then the limit is approximately 30kb ( which can be extended using the advanced interface).
Animation is an optional field that should be set if you have audio or movie media data.
nftTokenBuilder
  .setImage("ipfs://QmNoDT3M1FfF7d3Pd9DkBfzz8NxHueeudWBPe9owt1PnRM", "offchain")
  .setAnimation(
    "ipfs://QmTwnLtm7TkmaYJFrYFvsupedP3n51vu6czmVKiED5GyAX",
    "offchain"
  )
  .setDesc("This is my NFT")
  .setName("My NFT")
  .setAttributes({ key: "value", otherKey: "value" });
Mint a Token
Then we call mint on the tokenBuilder, which will mint a token from the contractAddr specified earlier. We can specify who we're minting to as well
const mintToAddress = nftContractBuilder.signer;
const tokenId = await nftTokenBuilder.mint(mintToAddress);
Putting it altogether
import { ClientFactory, lib, NftTokenBuilder } from "@1o1art/sdk";
import dotenv from "dotenv";
dotenv.config();
const PRIV_KEY = process.env.PRIV_KEY || "throw no private key set";
const RPC_URL = process.env.RPC_URL;
const main = async () => {
  const client = await ClientFactory.makeClient(PRIV_KEY, RPC_URL);
  const nftContractBuilder = client.createNftContractBuilder();
  // Get the components you'd like to add to your blank smart contract
  // basic will load the bare minimum to make a contract, delegatable
  // will provide a delegatable ERC721 token
  const contractFacets = await client.getPresetFacets("delegatable");
  // Create the contract and set a contract image
  const contractAddr = await nftContractBuilder
    .setFacets(contractFacets)
    .setImage(
      "ipfs://QmNoDT3M1FfF7d3Pd9DkBfzz8NxHueeudWBPe9owt1PnRM",
      "offchain"
    )
    .setMetadata({
      name: "My NFT",
      description: "This is my NFT",
      symbol: "API",
    })
    .deploy();
  // Prepare to create a token
  const nftTokenBuilder = new NftTokenBuilder(
    nftContractBuilder.signer,
    contractAddr
  );
  // This can be any address you'd like to mint to
  const mintToAddress = nftContractBuilder.signer.address;
  const tokenID = await nftTokenBuilder
    .setImage(
      "ipfs://QmNoDT3M1FfF7d3Pd9DkBfzz8NxHueeudWBPe9owt1PnRM",
      "offchain"
    )
    .setAnimation(
      "ipfs://QmTwnLtm7TkmaYJFrYFvsupedP3n51vu6czmVKiED5GyAX",
      "offchain"
    )
    .setDesc("This is my NFT")
    .setName("My NFT")
    .setAttributes({ key: "value", otherKey: "value" })
    .mint(mintToAddress);
  // get access to the recently launch NFT Contract
  const { nftContract } = await client.getNftContractData(contractAddr);
  // Use the contract to get the tokenURI aka the token Metadata
  const tokenURIBase64Encoded = await nftContract.tokenURI(tokenID);
  // get the token Metadata for the minted token
  let tokenMetadata: lib.token.TokenMetadata = JSON.parse(
    lib.utils.convertTokenUriData(tokenURIBase64Encoded)
  ) as lib.token.TokenMetadata;
  console.log(`Token Metadata: ${JSON.stringify(tokenMetadata, null, 2)}`);
};
main();