diff --git a/docs/react.md b/docs/react.md index 225ab23..f4122ca 100644 --- a/docs/react.md +++ b/docs/react.md @@ -80,6 +80,7 @@ import { useMetamask } from "@thirdweb-dev/react" ``` | | [useMintNFT(contract)](./react.usemintnft.md) | (BETA) Use this to mint a new NFT on your [NFTContract](./react.nftcontract.md) | +| [useMintNFTSupply(contract)](./react.usemintnftsupply.md) | (BETA) Use this to mint a new NFT on your [NFTContract](./react.nftcontract.md) | | [useMintToken(contract)](./react.useminttoken.md) | (BETA) Use this to mint new tokens on your contract | | [useMultiwrap(contractAddress)](./react.usemultiwrap.md) | Hook for getting an instance of an Multiwrap contract. This contract is an ERC721 in which you can wrap ERC721, ERC1155 and ERC20 tokens. | | [useNetwork()](./react.usenetwork.md) | Hook for getting metadata about the network the current wallet is connected to and switching networks | @@ -165,6 +166,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [MakeBidParams](./react.makebidparams.md) | | | [MintNFTParams](./react.mintnftparams.md) | (BETA) The params for the [useMintNFT()](./react.usemintnft.md) hook mutation. | | [MintNFTReturnType](./react.mintnftreturntype.md) | (BETA) The return type of the [useMintNFT()](./react.usemintnft.md) hook. | +| [MintNFTSupplyParams](./react.mintnftsupplyparams.md) | (BETA) The params to pass to useMintNFTSupply. | | [NFT](./react.nft.md) | (BETA) A single NFT token | | [NFTContract](./react.nftcontract.md) | (BETA) The possible NFT contract types. | | [RequiredParam](./react.requiredparam.md) | (BETA) Makes a parameter required to be passed, but still allowes it to be undefined. | diff --git a/docs/react.mintnftsupplyparams.md b/docs/react.mintnftsupplyparams.md new file mode 100644 index 0000000..fd559f7 --- /dev/null +++ b/docs/react.mintnftsupplyparams.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [MintNFTSupplyParams](./react.mintnftsupplyparams.md) + +## MintNFTSupplyParams type + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +The params to pass to `useMintNFTSupply`. + +Signature: + +```typescript +export declare type MintNFTSupplyParams = { + tokenId: BigNumberish; + additionalSupply: Amount; + to: WalletAddress; +}; +``` +References: [WalletAddress](./react.walletaddress.md) + diff --git a/docs/react.useburnnft.md b/docs/react.useburnnft.md index c625536..5c69a90 100644 --- a/docs/react.useburnnft.md +++ b/docs/react.useburnnft.md @@ -51,7 +51,7 @@ const Component = () => { disabled={isLoading} onClick={() => burnNft({ tokenId: 0 })} > - Mint! + Burn! ); }; diff --git a/docs/react.usemintnftsupply.md b/docs/react.usemintnftsupply.md new file mode 100644 index 0000000..196da65 --- /dev/null +++ b/docs/react.usemintnftsupply.md @@ -0,0 +1,95 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useMintNFTSupply](./react.usemintnftsupply.md) + +## useMintNFTSupply() function + +> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Use this to mint a new NFT on your [NFTContract](./react.nftcontract.md) + +Signature: + +```typescript +export declare function useMintNFTSupply(contract: Erc1155): import("@tanstack/react-query").UseMutationResult, unknown, MintNFTSupplyParams, unknown>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | Erc1155 | an instance of a | + +Returns: + +import("@tanstack/react-query").UseMutationResult<import("@thirdweb-dev/sdk/dist/browser").TransactionResultWithId<{ metadata: { \[x: string\]: import("@thirdweb-dev/sdk/dist/browser").Json; name?: string \| undefined; description?: string \| null \| undefined; image?: string \| null \| undefined; external\_url?: string \| null \| undefined; animation\_url?: string \| null \| undefined; uri: string; id: BigNumber; }; supply: BigNumber; }>, unknown, [MintNFTSupplyParams](./react.mintnftsupplyparams.md), unknown> + +a mutation object that can be used to mint a more supply of a token id to the provided wallet + +## Example 1 + + +```jsx +const Component = () => { + const nftDrop = useNFTDrop(); + const { + mutate: mintNftSupply, + isLoading, + error, + } = useMintNFTSupply(nftDrop); + + if (error) { + console.error("failed to mint additional supply", error); + } + + return ( + + ); +}; +``` + +## Example 2 + + +```jsx +const Component = () => { + const { contract } = useContract(); + const { + mutate: mintNftSupply, + isLoading, + error, + } = useMintNFTSupply(contract?.nft); + + if (error) { + console.error("failed to mint additional supply", error); + } + + return ( + + ); +}; +``` + diff --git a/etc/react.api.md b/etc/react.api.md index ae6b274..cfd7f66 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -233,6 +233,13 @@ export type MintNFTParams = TContract extends Erc // @beta export type MintNFTReturnType = TContract extends Erc721 ? Awaited> : TContract extends Erc1155 ? Awaited> : never; +// @beta +export type MintNFTSupplyParams = { + tokenId: BigNumberish; + additionalSupply: Amount; + to: WalletAddress; +}; + // @beta export type NFT = { metadata: NFTMetadata; @@ -1454,6 +1461,21 @@ export function useMetamask(): () => Promise<{ // @beta export function useMintNFT(contract: RequiredParam): UseMutationResult, unknown, MintNFTParams, unknown>; +// @beta +export function useMintNFTSupply(contract: Erc1155): UseMutationResult, unknown, MintNFTSupplyParams, unknown>; + // @beta export function useMintToken(contract: RequiredParam): UseMutationResult( ); } +/** + * Use this to mint a new NFT on your {@link NFTContract} + * + * @example + * ```jsx + * const Component = () => { + * const nftDrop = useNFTDrop(); + * const { + * mutate: mintNftSupply, + * isLoading, + * error, + * } = useMintNFTSupply(nftDrop); + * + * if (error) { + * console.error("failed to mint additional supply", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * @example + * ```jsx + * const Component = () => { + * const { contract } = useContract(); + * const { + * mutate: mintNftSupply, + * isLoading, + * error, + * } = useMintNFTSupply(contract?.nft); + * + * if (error) { + * console.error("failed to mint additional supply", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * + * @param contract - an instance of a {@link Erc1155} + * @returns a mutation object that can be used to mint a more supply of a token id to the provided wallet + * @beta + */ +export function useMintNFTSupply(contract: Erc1155) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + async (data: MintNFTSupplyParams) => { + invariant(data.to, 'No "to" address provided'); + invariant( + contract?.mint?.additionalSupplyTo, + "contract does not support mint.additionalSupplyTo", + ); + + invariant("tokenId" in data, "tokenId not provided"); + invariant("additionalSupply" in data, "additionalSupply not provided"); + const { to, tokenId, additionalSupply } = data; + return await contract.mint.additionalSupplyTo( + to, + tokenId, + additionalSupply, + ); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} + /** * Use this to transfer tokens on your {@link NFTContract} * @@ -630,7 +720,7 @@ export function useAirdropNFT(contract: Erc1155) { * disabled={isLoading} * onClick={() => burnNft({ tokenId: 0 })} * > - * Mint! + * Burn! * * ); * }; diff --git a/src/types.ts b/src/types.ts index 2f732ca..b1cdede 100644 --- a/src/types.ts +++ b/src/types.ts @@ -148,6 +148,16 @@ export type AirdropNFTParams = { addresses: AirdropInput; }; +/** + * The params to pass to `useMintNFTSupply`. + * @beta + */ +export type MintNFTSupplyParams = { + tokenId: BigNumberish; + additionalSupply: Amount; + to: WalletAddress; +}; + /** * The params for the {@link useMintNFT} hook mutation. *