> ## Documentation Index
> Fetch the complete documentation index at: https://docs.story.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# NFT Client

> Used to mint a new SPG collection for use with Story.

## NftClient

### Methods

* createNFTCollection
* getMintFeeToken
* getMintFee
* setTokenURI
* getTokenURI

### createNFTCollection

Creates a new SPG NFT Collection.

| Method                | Type                                                                            |
| --------------------- | ------------------------------------------------------------------------------- |
| `createNFTCollection` | `(request: CreateNFTCollectionRequest) => Promise<CreateNFTCollectionResponse>` |

Parameters:

* `request.name`: The name of the collection.
* `request.symbol`: The symbol of the collection.
* `request.isPublicMinting`: If true, anyone can mint from the collection. If false, only the addresses with the minter role can mint.
* `request.mintOpen`: Whether the collection is open for minting on creation.
* `request.mintFeeRecipient`: The address to receive mint fees.
* `request.contractURI`: The contract URI for the collection. Follows ERC-7572 standard. See [here](https://eips.ethereum.org/EIPS/eip-7572).
* `request.baseURI`: \[Optional] The base URI for the collection. If baseURI is not empty, tokenURI will be either baseURI + token ID (if nftMetadataURI is empty) or baseURI + nftMetadataURI.
* `request.maxSupply`: \[Optional] The maximum supply of the collection.
* `request.mintFee`: \[Optional] The cost to mint a token.
* `request.mintFeeToken`: \[Optional] The token to mint.
* `request.owner`: \[Optional] The owner of the collection.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { zeroAddress } from "viem";

  // Create a new SPG NFT collection
  //
  // NOTE: Use this code to create a new SPG NFT collection. You can then use the
  // `newCollection.spgNftContract` address as the `spgNftContract` argument in
  // functions like `registerIpAsset` in the IPAsset Client.
  //
  // You will mostly only have to do this once. Once you get your nft contract address,
  // you can use it in SPG functions.
  //
  const newCollection = await client.nftClient.createNFTCollection({
    name: "Test NFT",
    symbol: "TEST",
    isPublicMinting: true,
    mintOpen: true,
    mintFeeRecipient: zeroAddress,
    contractURI: "",
  });

  console.log(
    `New SPG NFT collection created at transaction hash ${newCollection.txHash}`
  );
  console.log(`NFT contract address: ${newCollection.spgNftContract}`);
  ```

  ```typescript Request Type theme={null}
  export type CreateNFTCollectionRequest = {
    name: string;
    symbol: string;
    isPublicMinting: boolean;
    mintOpen: boolean;
    mintFeeRecipient: Address;
    contractURI: string;
    baseURI?: string;
    maxSupply?: number;
    mintFee?: bigint;
    mintFeeToken?: Hex;
    owner?: Hex;
  };
  ```

  ```typescript Response Type theme={null}
  export type CreateNFTCollectionResponse = {
    txHash?: Hex;
    encodedTxData?: EncodedTxData;
    spgNftContract?: Address; // the address of the newly created contract
  };
  ```
</CodeGroup>

### getMintFeeToken

Returns the current mint token of the collection.

| Method            | Type                                            |
| ----------------- | ----------------------------------------------- |
| `getMintFeeToken` | `(spgNftContract: Address) => Promise<Address>` |

Parameters:

* `spgNftContract`: The address of the NFT contract.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const mintFeeToken = await client.nftClient.getMintFeeToken("0x01");
  ```
</CodeGroup>

### getMintFee

Returns the current mint fee of the collection.

| Method       | Type                                           |
| ------------ | ---------------------------------------------- |
| `getMintFee` | `(spgNftContract: Address) => Promise<bigint>` |

Parameters:

* `spgNftContract`: The address of the NFT contract.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const mintFee = await client.nftClient.getMintFee("0x01");
  ```
</CodeGroup>

### setTokenURI

Sets the token URI for a given token.

| Method        | Type                                                            |
| ------------- | --------------------------------------------------------------- |
| `setTokenURI` | `(request: SetTokenURIRequest) => Promise<TransactionResponse>` |

Parameters:

* `request.spgNftContract`: The address of the NFT contract.
* `request.tokenId`: The ID of the token.
* `request.tokenURI`: The URI to set.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const response = await client.nftClient.setTokenURI({
    spgNftContract: "0x01",
    tokenId: 1,
    tokenURI:
      "https://ipfs.io/ipfs/QmX4zdp8VpzqvtKuEqMo6gfZPdoUx9TeHXCgzKLcFfSUbk",
  });
  ```

  ```typescript Request Type theme={null}
  export type SetTokenURIRequest = {
    spgNftContract: Address;
    tokenId: bigint | number;
    tokenURI: string;
  };
  ```

  ```typescript Response Type theme={null}
  export type TransactionResponse = {
    txHash: Hex;
    /** Transaction receipt, only available if waitForTransaction is set to true */
    receipt?: TransactionReceipt;
  };
  ```
</CodeGroup>

### getTokenURI

Returns the token URI for a given token.

| Method        | Type                                               |
| ------------- | -------------------------------------------------- |
| `getTokenURI` | `(request: GetTokenURIRequest) => Promise<string>` |

Parameters:

* `request.spgNftContract`: The address of the SPG NFT contract.
* `request.tokenId`: The ID of the token.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const tokenURI = await client.nftClient.getTokenURI({
    spgNftContract: "0x01",
    tokenId: 1,
  });
  ```
</CodeGroup>

```typescript Request Type theme={null}
export type GetTokenURIRequest = {
  spgNftContract: Address;
  tokenId: bigint | number;
};
```
