From ae8b00926174775b499453646c7b2b93326ce65f Mon Sep 17 00:00:00 2001 From: Nacho Iacovino Date: Tue, 2 Aug 2022 02:58:43 +0200 Subject: [PATCH 1/9] Add transfer hooks --- src/hooks/async/token.ts | 116 +++++++++++++++++++++++++++++++++++++-- src/types.ts | 6 +- 2 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/hooks/async/token.ts b/src/hooks/async/token.ts index fac3f74..4b14b0c 100644 --- a/src/hooks/async/token.ts +++ b/src/hooks/async/token.ts @@ -2,7 +2,7 @@ import { useActiveChainId } from "../../Provider"; import { ClaimTokenParams, RequiredParam, - TokenMintParams, + TokenParams, WalletAddress, } from "../../types"; import { @@ -115,10 +115,10 @@ export function useMintToken(contract: RequiredParam) { const queryClient = useQueryClient(); return useMutation( - (data: TokenMintParams) => { - const { to, amount } = data; + (data: TokenParams) => { + const { toAddress, amount } = data; invariant(contract?.mint?.to, "contract does not support mint.to"); - return contract.mint.to(to, amount); + return contract.mint.to(toAddress, amount); }, { onSettled: () => @@ -189,3 +189,111 @@ export function useClaimToken( }, ); } + +/** + * Use this to mint a new NFT on your ERC20 contract + * + * @example + * ```jsx + * const Component = () => { + * const { + * mutate: mintNft, + * isLoading, + * error, + * } = useMintToken(">>YourERC20ContractInstance<<"); + * + * if (error) { + * console.error("failed to mint nft", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * + * @param contract - an instance of a contract that extends the ERC20 spec (token, token drop, custom contract that follows the ERC20 spec) + * @returns a mutation object that can be used to mint a new NFT token to the connected wallet + * @beta + */ +export function useTransferToken(contract: RequiredParam) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + (data: TokenParams) => { + const { toAddress, amount } = data; + invariant(contract?.transfer, "contract does not support transfer"); + return contract.transfer(toAddress, amount); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} + +/** + * Use this to mint a new NFT on your ERC20 contract + * + * @example + * ```jsx + * const Component = () => { + * const { + * mutate: mintNft, + * isLoading, + * error, + * } = useMintToken(">>YourERC20ContractInstance<<"); + * + * if (error) { + * console.error("failed to mint nft", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * + * @param contract - an instance of a contract that extends the ERC20 spec (token, token drop, custom contract that follows the ERC20 spec) + * @returns a mutation object that can be used to mint a new NFT token to the connected wallet + * @beta + */ +export function useTransferBatchToken(contract: RequiredParam) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + (data: TokenParams[]) => { + invariant( + contract?.transferBatch, + "contract does not support transferBatch", + ); + return contract.transferBatch(data); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} diff --git a/src/types.ts b/src/types.ts index d7a2e37..a2a915f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,12 +34,12 @@ export type WalletAddress = string; export type ContractAddress = string; /** - * The parameters to pass to the nft mint function. + * The parameters to pass to the nft mint and transfer functions. * * @beta */ -export type TokenMintParams = { - to: WalletAddress; +export type TokenParams = { + toAddress: WalletAddress; amount: string | number; }; From d259cb7c77db1304ac3149f9a7c7637967e03f10 Mon Sep 17 00:00:00 2001 From: Nacho Iacovino Date: Tue, 2 Aug 2022 03:03:31 +0200 Subject: [PATCH 2/9] yarn build --- docs/react.md | 4 +- ...okenmintparams.md => react.tokenparams.md} | 10 ++-- docs/react.useminttoken.md | 4 +- docs/react.usetransferbatchtoken.md | 55 ++++++++++++++++++ docs/react.usetransfertoken.md | 58 +++++++++++++++++++ etc/react.api.md | 15 ++++- 6 files changed, 135 insertions(+), 11 deletions(-) rename docs/{react.tokenmintparams.md => react.tokenparams.md} (67%) create mode 100644 docs/react.usetransferbatchtoken.md create mode 100644 docs/react.usetransfertoken.md diff --git a/docs/react.md b/docs/react.md index 84f3a43..d6ac6ee 100644 --- a/docs/react.md +++ b/docs/react.md @@ -107,6 +107,8 @@ import { useNetworkMistmatch } from "@thirdweb-dev/react" | [useTokenSupply(contract)](./react.usetokensupply.md) | (BETA) Use this to get a the total supply of your Token contract. | | [useTotalCirculatingSupply(\[contract, tokenId\])](./react.usetotalcirculatingsupply.md) |

(BETA) Use this to get a the total (minted) supply of your [NFTContract](./react.nftcontract.md).

\*

| | [useTotalCount(contract)](./react.usetotalcount.md) | (BETA) Use this to get a the number of tokens in your [NFTContract](./react.nftcontract.md). | +| [useTransferBatchToken(contract)](./react.usetransferbatchtoken.md) | (BETA) Use this to mint a new NFT on your ERC20 contract | +| [useTransferToken(contract)](./react.usetransfertoken.md) | (BETA) Use this to mint a new NFT on your ERC20 contract | | [useUnclaimedNFTs(contract, queryParams)](./react.useunclaimednfts.md) | (BETA) Use this to get a list of \*unclaimed\* NFT tokens of your ERC721 Drop contract. | | [useUnclaimedNFTSupply(contract)](./react.useunclaimednftsupply.md) | | | [useUpdateMetadata(contract)](./react.useupdatemetadata.md) | (BETA) Use this to update the metadata of your | @@ -159,7 +161,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [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. | -| [TokenMintParams](./react.tokenmintparams.md) | (BETA) The parameters to pass to the nft mint function. | +| [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the nft mint and transfer functions. | | [useNFTBalanceParams](./react.usenftbalanceparams.md) | (BETA) The params to pass to useNftBalance. | | [useTotalCirculatingSupplyParams](./react.usetotalcirculatingsupplyparams.md) | (BETA) The params to pass to useTotalCirculatingSupply. | | [WalletAddress](./react.walletaddress.md) | (BETA) A wallet address. | diff --git a/docs/react.tokenmintparams.md b/docs/react.tokenparams.md similarity index 67% rename from docs/react.tokenmintparams.md rename to docs/react.tokenparams.md index 1f24d64..177926c 100644 --- a/docs/react.tokenmintparams.md +++ b/docs/react.tokenparams.md @@ -1,19 +1,19 @@ -[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [TokenMintParams](./react.tokenmintparams.md) +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [TokenParams](./react.tokenparams.md) -## TokenMintParams type +## TokenParams 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 parameters to pass to the nft mint function. +The parameters to pass to the nft mint and transfer functions. Signature: ```typescript -export declare type TokenMintParams = { - to: WalletAddress; +export declare type TokenParams = { + toAddress: WalletAddress; amount: string | number; }; ``` diff --git a/docs/react.useminttoken.md b/docs/react.useminttoken.md index ccef132..6dc8481 100644 --- a/docs/react.useminttoken.md +++ b/docs/react.useminttoken.md @@ -15,7 +15,7 @@ Use this to mint a new NFT on your ERC20 contract export declare function useMintToken(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; -}, "data">, unknown, TokenMintParams, unknown>; +}, "data">, unknown, TokenParams, unknown>; ``` ## Parameters @@ -26,7 +26,7 @@ export declare function useMintToken(contract: RequiredParam): import("@t Returns: -import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenMintParams](./react.tokenmintparams.md), unknown> +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenParams](./react.tokenparams.md), unknown> a mutation object that can be used to mint a new NFT token to the connected wallet diff --git a/docs/react.usetransferbatchtoken.md b/docs/react.usetransferbatchtoken.md new file mode 100644 index 0000000..76c608d --- /dev/null +++ b/docs/react.usetransferbatchtoken.md @@ -0,0 +1,55 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferBatchToken](./react.usetransferbatchtoken.md) + +## useTransferBatchToken() 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 ERC20 contract + +Signature: + +```typescript +export declare function useTransferBatchToken(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | [RequiredParam](./react.requiredparam.md)<Erc20> | an instance of a contract that extends the ERC20 spec (token, token drop, custom contract that follows the ERC20 spec) | + +Returns: + +import("@tanstack/react-query").UseMutationResult<void, unknown, [TokenParams](./react.tokenparams.md)\[\], unknown> + +a mutation object that can be used to mint a new NFT token to the connected wallet + +## Example + + +```jsx +const Component = () => { + const { + mutate: mintNft, + isLoading, + error, + } = useMintToken(">>YourERC20ContractInstance<<"); + + if (error) { + console.error("failed to mint nft", error); + } + + return ( + + ); +}; +``` + diff --git a/docs/react.usetransfertoken.md b/docs/react.usetransfertoken.md new file mode 100644 index 0000000..0e2cc46 --- /dev/null +++ b/docs/react.usetransfertoken.md @@ -0,0 +1,58 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferToken](./react.usetransfertoken.md) + +## useTransferToken() 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 ERC20 contract + +Signature: + +```typescript +export declare function useTransferToken(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; +}, "data">, unknown, TokenParams, unknown>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | [RequiredParam](./react.requiredparam.md)<Erc20> | an instance of a contract that extends the ERC20 spec (token, token drop, custom contract that follows the ERC20 spec) | + +Returns: + +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenParams](./react.tokenparams.md), unknown> + +a mutation object that can be used to mint a new NFT token to the connected wallet + +## Example + + +```jsx +const Component = () => { + const { + mutate: mintNft, + isLoading, + error, + } = useMintToken(">>YourERC20ContractInstance<<"); + + if (error) { + console.error("failed to mint nft", error); + } + + return ( + + ); +}; +``` + diff --git a/etc/react.api.md b/etc/react.api.md index 4b57c54..e11afad 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -291,8 +291,8 @@ export interface ThirdwebSDKProviderProps extends Pick(contract: RequiredPara export function useMintToken(contract: RequiredParam): UseMutationResult Promise; -}, "data">, unknown, TokenMintParams, unknown>; +}, "data">, unknown, TokenParams, unknown>; // @public export function useMultiwrap(contractAddress?: string): Multiwrap | undefined; @@ -1569,6 +1569,15 @@ export type useTotalCirculatingSupplyParams = TContract extends Erc11 // @beta export function useTotalCount(contract: RequiredParam): UseQueryResult; +// @beta +export function useTransferBatchToken(contract: RequiredParam): UseMutationResult; + +// @beta +export function useTransferToken(contract: RequiredParam): UseMutationResult Promise; +}, "data">, unknown, TokenParams, unknown>; + // @beta export function useUnclaimedNFTs(contract: RequiredParam, queryParams?: QueryAllParams): UseQueryResult< { [x: string]: Json; From caf57bb8015466bfbee213a85da5b554498a8428 Mon Sep 17 00:00:00 2001 From: Nacho Iacovino Date: Wed, 3 Aug 2022 02:05:18 +0200 Subject: [PATCH 3/9] Fix docs, fix breaking changes --- docs/react.md | 13 +++++---- docs/react.tokenmintparams.md | 21 ++++++++++++++ docs/react.tokenparams.md | 2 +- docs/react.useclaimtoken.md | 2 +- docs/react.useminttoken.md | 12 ++++---- docs/react.usetokenbalance.md | 2 +- docs/react.usetokensupply.md | 2 +- docs/react.usetransferbatchtoken.md | 12 ++++---- docs/react.usetransfertoken.md | 12 ++++---- docs/snippets.json | 6 ++-- etc/react.api.md | 12 ++++++-- src/hooks/async/token.ts | 45 +++++++++++++++-------------- src/types.ts | 12 +++++++- 13 files changed, 96 insertions(+), 57 deletions(-) create mode 100644 docs/react.tokenmintparams.md diff --git a/docs/react.md b/docs/react.md index d6ac6ee..86c0d8f 100644 --- a/docs/react.md +++ b/docs/react.md @@ -77,7 +77,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) | -| [useMintToken(contract)](./react.useminttoken.md) | (BETA) Use this to mint a new NFT on your ERC20 contract | +| [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 | | [useNetworkMismatch()](./react.usenetworkmismatch.md) |

Hook for checking whether the connected wallet is on the correct network specified by the desiredChainId passed to the <ThirdwebProvider />.

@@ -103,12 +103,12 @@ import { useNetworkMistmatch } from "@thirdweb-dev/react" | [useSignatureDrop(contractAddress)](./react.usesignaturedrop.md) | Hook for getting an instance of an SignatureDrop contract. This contract is meant to interface with ERC721 compliant NFTs that can be lazily minted. | | [useSplit(contractAddress)](./react.usesplit.md) | Hook for getting an instance of a Split contract. This contract supports fund distribution to multiple parties. | | [useToken(contractAddress)](./react.usetoken.md) | Hook for getting an instance of an Token contract. This contract supports ERC20 compliant tokens. | -| [useTokenBalance(contract, walletAddress)](./react.usetokenbalance.md) | (BETA) Use this to get the balance of your Token contract for a given address. | -| [useTokenSupply(contract)](./react.usetokensupply.md) | (BETA) Use this to get a the total supply of your Token contract. | +| [useTokenBalance(contract, walletAddress)](./react.usetokenbalance.md) | (BETA) Use this to get the balance of your contract for a given address. | +| [useTokenSupply(contract)](./react.usetokensupply.md) | (BETA) Use this to get a the total supply of your contract. | | [useTotalCirculatingSupply(\[contract, tokenId\])](./react.usetotalcirculatingsupply.md) |

(BETA) Use this to get a the total (minted) supply of your [NFTContract](./react.nftcontract.md).

\*

| | [useTotalCount(contract)](./react.usetotalcount.md) | (BETA) Use this to get a the number of tokens in your [NFTContract](./react.nftcontract.md). | -| [useTransferBatchToken(contract)](./react.usetransferbatchtoken.md) | (BETA) Use this to mint a new NFT on your ERC20 contract | -| [useTransferToken(contract)](./react.usetransfertoken.md) | (BETA) Use this to mint a new NFT on your ERC20 contract | +| [useTransferBatchToken(contract)](./react.usetransferbatchtoken.md) | (BETA) Use this to transfer batch tokens on your contract | +| [useTransferToken(contract)](./react.usetransfertoken.md) | (BETA) Use this to transfer tokens on your contract | | [useUnclaimedNFTs(contract, queryParams)](./react.useunclaimednfts.md) | (BETA) Use this to get a list of \*unclaimed\* NFT tokens of your ERC721 Drop contract. | | [useUnclaimedNFTSupply(contract)](./react.useunclaimednftsupply.md) | | | [useUpdateMetadata(contract)](./react.useupdatemetadata.md) | (BETA) Use this to update the metadata of your | @@ -161,7 +161,8 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [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. | -| [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the nft mint and transfer functions. | +| [TokenMintParams](./react.tokenmintparams.md) | (BETA) The parameters to pass to the NFT mint functions. | +| [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the NFT transfer functions. | | [useNFTBalanceParams](./react.usenftbalanceparams.md) | (BETA) The params to pass to useNftBalance. | | [useTotalCirculatingSupplyParams](./react.usetotalcirculatingsupplyparams.md) | (BETA) The params to pass to useTotalCirculatingSupply. | | [WalletAddress](./react.walletaddress.md) | (BETA) A wallet address. | diff --git a/docs/react.tokenmintparams.md b/docs/react.tokenmintparams.md new file mode 100644 index 0000000..9e13203 --- /dev/null +++ b/docs/react.tokenmintparams.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [TokenMintParams](./react.tokenmintparams.md) + +## TokenMintParams 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 parameters to pass to the NFT mint functions. + +Signature: + +```typescript +export declare type TokenMintParams = { + to: WalletAddress; + amount: string | number; +}; +``` +References: [WalletAddress](./react.walletaddress.md) + diff --git a/docs/react.tokenparams.md b/docs/react.tokenparams.md index 177926c..c261d4d 100644 --- a/docs/react.tokenparams.md +++ b/docs/react.tokenparams.md @@ -7,7 +7,7 @@ > 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 parameters to pass to the nft mint and transfer functions. +The parameters to pass to the NFT transfer functions. Signature: diff --git a/docs/react.useclaimtoken.md b/docs/react.useclaimtoken.md index 5422ce9..ae701b2 100644 --- a/docs/react.useclaimtoken.md +++ b/docs/react.useclaimtoken.md @@ -48,7 +48,7 @@ const Component = () => { return ( diff --git a/docs/react.useminttoken.md b/docs/react.useminttoken.md index 6dc8481..7932240 100644 --- a/docs/react.useminttoken.md +++ b/docs/react.useminttoken.md @@ -7,7 +7,7 @@ > 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 ERC20 contract +Use this to mint new tokens on your contract Signature: @@ -15,7 +15,7 @@ Use this to mint a new NFT on your ERC20 contract export declare function useMintToken(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; -}, "data">, unknown, TokenParams, unknown>; +}, "data">, unknown, TokenMintParams, unknown>; ``` ## Parameters @@ -26,7 +26,7 @@ export declare function useMintToken(contract: RequiredParam): import("@t Returns: -import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenParams](./react.tokenparams.md), unknown> +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenMintParams](./react.tokenmintparams.md), unknown> a mutation object that can be used to mint a new NFT token to the connected wallet @@ -36,19 +36,19 @@ a mutation object that can be used to mint a new NFT token to the connected wall ```jsx const Component = () => { const { - mutate: mintNft, + mutate: mintTokens, isLoading, error, } = useMintToken(">>YourERC20ContractInstance<<"); if (error) { - console.error("failed to mint nft", error); + console.error("failed to mint tokens", error); } return ( diff --git a/docs/react.usetokenbalance.md b/docs/react.usetokenbalance.md index 809ac21..80bd951 100644 --- a/docs/react.usetokenbalance.md +++ b/docs/react.usetokenbalance.md @@ -7,7 +7,7 @@ > 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 get the balance of your Token contract for a given address. +Use this to get the balance of your contract for a given address. Signature: diff --git a/docs/react.usetokensupply.md b/docs/react.usetokensupply.md index d4e7887..a2aef55 100644 --- a/docs/react.usetokensupply.md +++ b/docs/react.usetokensupply.md @@ -7,7 +7,7 @@ > 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 get a the total supply of your Token contract. +Use this to get a the total supply of your contract. Signature: diff --git a/docs/react.usetransferbatchtoken.md b/docs/react.usetransferbatchtoken.md index 76c608d..34504ca 100644 --- a/docs/react.usetransferbatchtoken.md +++ b/docs/react.usetransferbatchtoken.md @@ -7,7 +7,7 @@ > 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 ERC20 contract +Use this to transfer batch tokens on your contract Signature: @@ -33,21 +33,21 @@ a mutation object that can be used to mint a new NFT token to the connected wall ```jsx const Component = () => { const { - mutate: mintNft, + mutate: transferBatchTokens, isLoading, error, - } = useMintToken(">>YourERC20ContractInstance<<"); + } = useTransferToken(">>YourERC20ContractInstance<<"); if (error) { - console.error("failed to mint nft", error); + console.error("failed to transfer batch tokens", error); } return ( ); }; diff --git a/docs/react.usetransfertoken.md b/docs/react.usetransfertoken.md index 0e2cc46..2dd1895 100644 --- a/docs/react.usetransfertoken.md +++ b/docs/react.usetransfertoken.md @@ -7,7 +7,7 @@ > 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 ERC20 contract +Use this to transfer tokens on your contract Signature: @@ -36,21 +36,21 @@ a mutation object that can be used to mint a new NFT token to the connected wall ```jsx const Component = () => { const { - mutate: mintNft, + mutate: transferTokens, isLoading, error, - } = useMintToken(">>YourERC20ContractInstance<<"); + } = useTransferToken(">>YourERC20ContractInstance<<"); if (error) { - console.error("failed to mint nft", error); + console.error("failed to transfer tokens", error); } return ( ); }; diff --git a/docs/snippets.json b/docs/snippets.json index f317900..d8da7ed 100644 --- a/docs/snippets.json +++ b/docs/snippets.json @@ -238,7 +238,7 @@ }, { "name": "useClaimToken", - "example": "const Component = () => {\n const {\n mutate: claimTokens,\n isLoading,\n error,\n } = useClaimToken(TokenDropContract);\n\n if (error) {\n console.error(\"failed to claim tokens\", error);\n }\n\n return (\n claimTokens({to: \"0x...\", amount: 100})}\n >\n Claim Tokens!\n \n );\n};", + "example": "const Component = () => {\n const {\n mutate: claimTokens,\n isLoading,\n error,\n } = useClaimToken(TokenDropContract);\n\n if (error) {\n console.error(\"failed to claim tokens\", error);\n }\n\n return (\n claimTokens({ to: \"0x...\", amount: 100 })}\n >\n Claim Tokens!\n \n );\n};", "reference": "https://portal.thirdweb.com/react/react.useclaimtoken" }, { @@ -423,7 +423,7 @@ }, { "name": "useClaimToken", - "example": "const Component = () => {\n const {\n mutate: claimTokens,\n isLoading,\n error,\n } = useClaimToken(TokenDropContract);\n\n if (error) {\n console.error(\"failed to claim tokens\", error);\n }\n\n return (\n claimTokens({to: \"0x...\", amount: 100})}\n >\n Claim Tokens!\n \n );\n};", + "example": "const Component = () => {\n const {\n mutate: claimTokens,\n isLoading,\n error,\n } = useClaimToken(TokenDropContract);\n\n if (error) {\n console.error(\"failed to claim tokens\", error);\n }\n\n return (\n claimTokens({ to: \"0x...\", amount: 100 })}\n >\n Claim Tokens!\n \n );\n};", "reference": "https://portal.thirdweb.com/react/react.useclaimtoken" }, { @@ -527,7 +527,7 @@ "subhooks": [ { "name": "useMintToken", - "example": "const Component = () => {\n const {\n mutate: mintNft,\n isLoading,\n error,\n } = useMintToken(\">>YourERC20ContractInstance<<\");\n\n if (error) {\n console.error(\"failed to mint nft\", error);\n }\n\n return (\n mintNft({ name: \"My awesome NFT!\" })}\n >\n Mint!\n \n );\n};", + "example": "const Component = () => {\n const {\n mutate: mintTokens,\n isLoading,\n error,\n } = useMintToken(\">>YourERC20ContractInstance<<\");\n\n if (error) {\n console.error(\"failed to mint tokens\", error);\n }\n\n return (\n mintTokens({ to: \"0x...\", amount: 1000 })}\n >\n Mint!\n \n );\n};", "reference": "https://portal.thirdweb.com/react/react.useminttoken" }, { diff --git a/etc/react.api.md b/etc/react.api.md index e11afad..00310e5 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -290,6 +290,12 @@ export interface ThirdwebSDKProviderProps extends Pick(contract: RequiredPara export function useMintToken(contract: RequiredParam): UseMutationResult Promise; -}, "data">, unknown, TokenParams, unknown>; +}, "data">, unknown, TokenMintParams, unknown>; // @public export function useMultiwrap(contractAddress?: string): Multiwrap | undefined; @@ -1685,8 +1691,8 @@ export type WalletLinkConnectorType = "walletLink" | "coinbase" | { // dist/hooks/async/roles.d.ts:126:5 - (ae-incompatible-release-tags) The symbol "role" is marked as @beta, but its signature references "RolesForContract" which is marked as @internal // dist/hooks/async/roles.d.ts:161:5 - (ae-incompatible-release-tags) The symbol "role" is marked as @beta, but its signature references "RolesForContract" which is marked as @internal // dist/hooks/useNetwork.d.ts:48:5 - (ae-forgotten-export) The symbol "SwitchChainError" needs to be exported by the entry point index.d.ts -// dist/types.d.ts:148:5 - (ae-incompatible-release-tags) The symbol "buyForWallet" is marked as @public, but its signature references "WalletAddress" which is marked as @beta -// dist/types.d.ts:154:5 - (ae-incompatible-release-tags) The symbol "to" is marked as @public, but its signature references "WalletAddress" which is marked as @beta +// dist/types.d.ts:157:5 - (ae-incompatible-release-tags) The symbol "buyForWallet" is marked as @public, but its signature references "WalletAddress" which is marked as @beta +// dist/types.d.ts:163:5 - (ae-incompatible-release-tags) The symbol "to" is marked as @public, but its signature references "WalletAddress" which is marked as @beta // (No @packageDocumentation comment for this package) diff --git a/src/hooks/async/token.ts b/src/hooks/async/token.ts index 4b14b0c..fed0a54 100644 --- a/src/hooks/async/token.ts +++ b/src/hooks/async/token.ts @@ -2,6 +2,7 @@ import { useActiveChainId } from "../../Provider"; import { ClaimTokenParams, RequiredParam, + TokenMintParams, TokenParams, WalletAddress, } from "../../types"; @@ -19,7 +20,7 @@ import invariant from "tiny-invariant"; /** **********************/ /** - * Use this to get a the total supply of your Token contract. + * Use this to get a the total supply of your {@link Erc20} contract. * * @example * ```javascript @@ -45,7 +46,7 @@ export function useTokenSupply(contract: RequiredParam) { } /** - * Use this to get the balance of your Token contract for a given address. + * Use this to get the balance of your {@link Erc20} contract for a given address. * * @example * ```javascript @@ -79,25 +80,25 @@ export function useTokenBalance( /** **********************/ /** - * Use this to mint a new NFT on your ERC20 contract + * Use this to mint new tokens on your {@link Erc20} contract * * @example * ```jsx * const Component = () => { * const { - * mutate: mintNft, + * mutate: mintTokens, * isLoading, * error, * } = useMintToken(">>YourERC20ContractInstance<<"); * * if (error) { - * console.error("failed to mint nft", error); + * console.error("failed to mint tokens", error); * } * * return ( * @@ -115,10 +116,10 @@ export function useMintToken(contract: RequiredParam) { const queryClient = useQueryClient(); return useMutation( - (data: TokenParams) => { - const { toAddress, amount } = data; + (data: TokenMintParams) => { + const { to, amount } = data; invariant(contract?.mint?.to, "contract does not support mint.to"); - return contract.mint.to(toAddress, amount); + return contract.mint.to(to, amount); }, { onSettled: () => @@ -150,7 +151,7 @@ export function useMintToken(contract: RequiredParam) { * return ( * @@ -191,27 +192,27 @@ export function useClaimToken( } /** - * Use this to mint a new NFT on your ERC20 contract + * Use this to transfer tokens on your {@link Erc20} contract * * @example * ```jsx * const Component = () => { * const { - * mutate: mintNft, + * mutate: transferTokens, * isLoading, * error, - * } = useMintToken(">>YourERC20ContractInstance<<"); + * } = useTransferToken(">>YourERC20ContractInstance<<"); * * if (error) { - * console.error("failed to mint nft", error); + * console.error("failed to transfer tokens", error); * } * * return ( * * ); * }; @@ -244,27 +245,27 @@ export function useTransferToken(contract: RequiredParam) { } /** - * Use this to mint a new NFT on your ERC20 contract + * Use this to transfer batch tokens on your {@link Erc20} contract * * @example * ```jsx * const Component = () => { * const { - * mutate: mintNft, + * mutate: transferBatchTokens, * isLoading, * error, - * } = useMintToken(">>YourERC20ContractInstance<<"); + * } = useTransferToken(">>YourERC20ContractInstance<<"); * * if (error) { - * console.error("failed to mint nft", error); + * console.error("failed to transfer batch tokens", error); * } * * return ( * * ); * }; diff --git a/src/types.ts b/src/types.ts index a2a915f..679da84 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,7 +34,17 @@ export type WalletAddress = string; export type ContractAddress = string; /** - * The parameters to pass to the nft mint and transfer functions. + * The parameters to pass to the NFT mint functions. + * + * @beta + */ +export type TokenMintParams = { + to: WalletAddress; + amount: string | number; +}; + +/** + * The parameters to pass to the NFT transfer functions. * * @beta */ From 56b960a110045470d406425f3da8ab9be3196089 Mon Sep 17 00:00:00 2001 From: Nacho Iacovino Date: Wed, 3 Aug 2022 19:27:46 +0200 Subject: [PATCH 4/9] Unify interface --- docs/react.md | 3 +-- docs/react.tokenmintparams.md | 21 --------------------- docs/react.tokenparams.md | 4 ++-- docs/react.useminttoken.md | 4 ++-- docs/react.usetransferbatchtoken.md | 2 +- docs/react.usetransfertoken.md | 2 +- etc/react.api.md | 14 ++++---------- src/hooks/async/token.ts | 18 +++++++++++------- src/types.ts | 14 ++------------ 9 files changed, 24 insertions(+), 58 deletions(-) delete mode 100644 docs/react.tokenmintparams.md diff --git a/docs/react.md b/docs/react.md index 86c0d8f..530b15f 100644 --- a/docs/react.md +++ b/docs/react.md @@ -161,8 +161,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [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. | -| [TokenMintParams](./react.tokenmintparams.md) | (BETA) The parameters to pass to the NFT mint functions. | -| [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the NFT transfer functions. | +| [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the mint and transfer functions. | | [useNFTBalanceParams](./react.usenftbalanceparams.md) | (BETA) The params to pass to useNftBalance. | | [useTotalCirculatingSupplyParams](./react.usetotalcirculatingsupplyparams.md) | (BETA) The params to pass to useTotalCirculatingSupply. | | [WalletAddress](./react.walletaddress.md) | (BETA) A wallet address. | diff --git a/docs/react.tokenmintparams.md b/docs/react.tokenmintparams.md deleted file mode 100644 index 9e13203..0000000 --- a/docs/react.tokenmintparams.md +++ /dev/null @@ -1,21 +0,0 @@ - - -[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [TokenMintParams](./react.tokenmintparams.md) - -## TokenMintParams 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 parameters to pass to the NFT mint functions. - -Signature: - -```typescript -export declare type TokenMintParams = { - to: WalletAddress; - amount: string | number; -}; -``` -References: [WalletAddress](./react.walletaddress.md) - diff --git a/docs/react.tokenparams.md b/docs/react.tokenparams.md index c261d4d..0034cea 100644 --- a/docs/react.tokenparams.md +++ b/docs/react.tokenparams.md @@ -7,13 +7,13 @@ > 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 parameters to pass to the NFT transfer functions. +The parameters to pass to the mint and transfer functions. Signature: ```typescript export declare type TokenParams = { - toAddress: WalletAddress; + to: WalletAddress; amount: string | number; }; ``` diff --git a/docs/react.useminttoken.md b/docs/react.useminttoken.md index 7932240..08621c2 100644 --- a/docs/react.useminttoken.md +++ b/docs/react.useminttoken.md @@ -15,7 +15,7 @@ Use this to mint new tokens on your contract export declare function useMintToken(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; -}, "data">, unknown, TokenMintParams, unknown>; +}, "data">, unknown, TokenParams, unknown>; ``` ## Parameters @@ -26,7 +26,7 @@ export declare function useMintToken(contract: RequiredParam): import("@t Returns: -import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenMintParams](./react.tokenmintparams.md), unknown> +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TokenParams](./react.tokenparams.md), unknown> a mutation object that can be used to mint a new NFT token to the connected wallet diff --git a/docs/react.usetransferbatchtoken.md b/docs/react.usetransferbatchtoken.md index 34504ca..4f18995 100644 --- a/docs/react.usetransferbatchtoken.md +++ b/docs/react.usetransferbatchtoken.md @@ -45,7 +45,7 @@ const Component = () => { return ( diff --git a/docs/react.usetransfertoken.md b/docs/react.usetransfertoken.md index 2dd1895..d875a28 100644 --- a/docs/react.usetransfertoken.md +++ b/docs/react.usetransfertoken.md @@ -48,7 +48,7 @@ const Component = () => { return ( diff --git a/etc/react.api.md b/etc/react.api.md index cb00df4..7ec1b32 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -292,15 +292,9 @@ export interface ThirdwebSDKProviderProps extends Pick(contract: RequiredPara export function useMintToken(contract: RequiredParam): UseMutationResult Promise; -}, "data">, unknown, TokenMintParams, unknown>; +}, "data">, unknown, TokenParams, unknown>; // @public export function useMultiwrap(contractAddress?: string): Multiwrap | undefined; @@ -1693,8 +1687,8 @@ export type WalletLinkConnectorType = "walletLink" | "coinbase" | { // dist/hooks/async/roles.d.ts:126:5 - (ae-incompatible-release-tags) The symbol "role" is marked as @beta, but its signature references "RolesForContract" which is marked as @internal // dist/hooks/async/roles.d.ts:161:5 - (ae-incompatible-release-tags) The symbol "role" is marked as @beta, but its signature references "RolesForContract" which is marked as @internal // dist/hooks/useNetwork.d.ts:48:5 - (ae-forgotten-export) The symbol "SwitchChainError" needs to be exported by the entry point index.d.ts -// dist/types.d.ts:157:5 - (ae-incompatible-release-tags) The symbol "buyForWallet" is marked as @public, but its signature references "WalletAddress" which is marked as @beta -// dist/types.d.ts:163:5 - (ae-incompatible-release-tags) The symbol "to" is marked as @public, but its signature references "WalletAddress" which is marked as @beta +// dist/types.d.ts:148:5 - (ae-incompatible-release-tags) The symbol "buyForWallet" is marked as @public, but its signature references "WalletAddress" which is marked as @beta +// dist/types.d.ts:154:5 - (ae-incompatible-release-tags) The symbol "to" is marked as @public, but its signature references "WalletAddress" which is marked as @beta // (No @packageDocumentation comment for this package) diff --git a/src/hooks/async/token.ts b/src/hooks/async/token.ts index fed0a54..766d5c1 100644 --- a/src/hooks/async/token.ts +++ b/src/hooks/async/token.ts @@ -2,7 +2,6 @@ import { useActiveChainId } from "../../Provider"; import { ClaimTokenParams, RequiredParam, - TokenMintParams, TokenParams, WalletAddress, } from "../../types"; @@ -116,7 +115,7 @@ export function useMintToken(contract: RequiredParam) { const queryClient = useQueryClient(); return useMutation( - (data: TokenMintParams) => { + (data: TokenParams) => { const { to, amount } = data; invariant(contract?.mint?.to, "contract does not support mint.to"); return contract.mint.to(to, amount); @@ -210,7 +209,7 @@ export function useClaimToken( * return ( * @@ -229,9 +228,9 @@ export function useTransferToken(contract: RequiredParam) { return useMutation( (data: TokenParams) => { - const { toAddress, amount } = data; + const { to, amount } = data; invariant(contract?.transfer, "contract does not support transfer"); - return contract.transfer(toAddress, amount); + return contract.transfer(to, amount); }, { onSettled: () => @@ -263,7 +262,7 @@ export function useTransferToken(contract: RequiredParam) { * return ( * @@ -286,7 +285,12 @@ export function useTransferBatchToken(contract: RequiredParam) { contract?.transferBatch, "contract does not support transferBatch", ); - return contract.transferBatch(data); + const convertedData = data.map((token) => ({ + toAddress: token.to, + amount: token.amount, + })); + + return contract.transferBatch(convertedData); }, { onSettled: () => diff --git a/src/types.ts b/src/types.ts index 679da84..79f3e44 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,22 +34,12 @@ export type WalletAddress = string; export type ContractAddress = string; /** - * The parameters to pass to the NFT mint functions. - * - * @beta - */ -export type TokenMintParams = { - to: WalletAddress; - amount: string | number; -}; - -/** - * The parameters to pass to the NFT transfer functions. + * The parameters to pass to the mint and transfer functions. * * @beta */ export type TokenParams = { - toAddress: WalletAddress; + to: WalletAddress; amount: string | number; }; From 1620919cc924fc32a3f32eab13c5ca5ecee83106 Mon Sep 17 00:00:00 2001 From: Nacho Iacovino Date: Wed, 3 Aug 2022 22:02:00 +0200 Subject: [PATCH 5/9] Add transfer and transferBatch for NFTs --- src/hooks/async/nft.ts | 173 ++++++++++++++++++++++++++++++++++++++++- src/types.ts | 18 +++++ 2 files changed, 189 insertions(+), 2 deletions(-) diff --git a/src/hooks/async/nft.ts b/src/hooks/async/nft.ts index 397dd45..4eba03a 100644 --- a/src/hooks/async/nft.ts +++ b/src/hooks/async/nft.ts @@ -8,14 +8,16 @@ import { WalletAddress, useNFTBalanceParams, useTotalCirculatingSupplyParams, + useTransferBatchNFTParams, + useTransferNFTParams, } from "../../types"; import { cacheKeys, invalidateContractAndBalances, } from "../../utils/cache-keys"; import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork"; -import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { QueryAllParams } from "@thirdweb-dev/sdk/dist/browser"; +import { Mutation, useMutation, useQueryClient } from "@tanstack/react-query"; +import { AirdropInput, QueryAllParams } from "@thirdweb-dev/sdk/dist/browser"; // eslint-disable-next-line no-duplicate-imports import { Erc721, Erc1155 } from "@thirdweb-dev/sdk/dist/browser"; import { BigNumber, BigNumberish } from "ethers"; @@ -431,3 +433,170 @@ export function useMintNFT( }, ); } + +/** + * Use this to transfer tokens on your {@link NFTContract} + * + * @example + * ```jsx + * const Component = () => { + * const nftDrop = useNFTDrop(); + * const { + * mutate: transferNFT, + * isLoading, + * error, + * } = useTransferNFT(nftDrop); + * + * if (error) { + * console.error("failed to transfer nft", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * @example + * ```jsx + * const Component = () => { + * const { contract } = useContract(); + * const { + * mutate: transferNFT, + * isLoading, + * error, + * } = useTransferNFT(contract?.nft); + * + * if (error) { + * console.error("failed to transfer nft", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * + * @param contract - an instance of a {@link NFTContract} + * @returns a mutation object that can be used to transfer NFTs + * @beta + */ +export function useTransferNFT( + contract: RequiredParam, +) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + (data: useTransferNFTParams) => { + invariant(contract?.transfer, "contract does not support transfer"); + if (contract instanceof Erc1155) { + invariant(data.amount, "amount not provided"); + return contract.transfer(data.to, data.tokenId, data.amount); + } + + return contract.transfer(data.to, data.tokenId); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} + +/** + * Use this to transfer tokens on your {@link Erc1155} + * + * @example + * ```jsx + * const Component = () => { + * const editionDrop = useEditionDrop(); + * const { + * mutate: transferBatchNFTs, + * isLoading, + * error, + * } = useTransferBatchNFT(editionDrop); + * + * if (error) { + * console.error("failed to transfer batch NFTs", error); + * } + * + * return ( + * + * }; + * ``` + * @example + * ```jsx + * const Component = () => { + * const { contract } = useContract(); + * const { + * mutate: transferBatchNFTs, + * isLoading, + * error, + * } = useTransferBatchNFT(contract?.nft); + * + * if (error) { + * console.error("failed to transfer batch NFTs", error); + * } + * + * return ( + * + * ); + * }; + * ``` + * + * @param contract - an instance of a {@link Erc1155} + * @returns a mutation object that can be used to transfer batch NFTs + * @beta + */ +export function useTransferBatchNFT(contract: Erc1155) { + const activeChainId = useActiveChainId(); + const contractAddress = contract?.getAddress(); + const queryClient = useQueryClient(); + + return useMutation( + ({ tokenId, addresses }: useTransferBatchNFTParams) => { + invariant(contract?.airdrop, "contract does not support transferBatch"); + + return contract.airdrop(tokenId, addresses); + }, + { + onSettled: () => + invalidateContractAndBalances( + queryClient, + contractAddress, + activeChainId, + ), + }, + ); +} diff --git a/src/types.ts b/src/types.ts index 79f3e44..811dbcb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import type { + AirdropInput, Amount, EditionDrop, Erc721, @@ -106,6 +107,23 @@ export type useTotalCirculatingSupplyParams = ? [contract: RequiredParam, tokenId: BigNumberish] : [contract: RequiredParam]; +/** + * The params to pass to `useTransferNFT`. + * @beta + */ +export type useTransferNFTParams = TContract extends Erc1155 + ? { to: string; tokenId: BigNumberish; amount: string | number } + : { to: string; tokenId: BigNumberish; amount?: never }; + +/** + * The params to pass to `useTransferBatchNFT`. + * @beta + */ +export type useTransferBatchNFTParams = { + tokenId: BigNumberish; + addresses: AirdropInput; +}; + /** * The params to pass to `useNftBalance`. * @beta From 40e07e333bd5af4c901e5668b7508a4c2b9a5e49 Mon Sep 17 00:00:00 2001 From: Nacho Iacovino Date: Wed, 3 Aug 2022 22:02:30 +0200 Subject: [PATCH 6/9] yarn build --- docs/react.md | 4 ++ docs/react.usetransferbatchnft.md | 91 +++++++++++++++++++++++++ docs/react.usetransferbatchnftparams.md | 19 ++++++ docs/react.usetransfernft.md | 86 +++++++++++++++++++++++ docs/react.usetransfernftparams.md | 24 +++++++ etc/react.api.md | 34 ++++++++- src/hooks/async/nft.ts | 4 +- 7 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 docs/react.usetransferbatchnft.md create mode 100644 docs/react.usetransferbatchnftparams.md create mode 100644 docs/react.usetransfernft.md create mode 100644 docs/react.usetransfernftparams.md diff --git a/docs/react.md b/docs/react.md index 530b15f..c5d01e2 100644 --- a/docs/react.md +++ b/docs/react.md @@ -107,7 +107,9 @@ import { useNetworkMistmatch } from "@thirdweb-dev/react" | [useTokenSupply(contract)](./react.usetokensupply.md) | (BETA) Use this to get a the total supply of your contract. | | [useTotalCirculatingSupply(\[contract, tokenId\])](./react.usetotalcirculatingsupply.md) |

(BETA) Use this to get a the total (minted) supply of your [NFTContract](./react.nftcontract.md).

\*

| | [useTotalCount(contract)](./react.usetotalcount.md) | (BETA) Use this to get a the number of tokens in your [NFTContract](./react.nftcontract.md). | +| [useTransferBatchNFT(contract)](./react.usetransferbatchnft.md) | (BETA) Use this to transfer tokens on your | | [useTransferBatchToken(contract)](./react.usetransferbatchtoken.md) | (BETA) Use this to transfer batch tokens on your contract | +| [useTransferNFT(contract)](./react.usetransfernft.md) | (BETA) Use this to transfer tokens on your [NFTContract](./react.nftcontract.md) | | [useTransferToken(contract)](./react.usetransfertoken.md) | (BETA) Use this to transfer tokens on your contract | | [useUnclaimedNFTs(contract, queryParams)](./react.useunclaimednfts.md) | (BETA) Use this to get a list of \*unclaimed\* NFT tokens of your ERC721 Drop contract. | | [useUnclaimedNFTSupply(contract)](./react.useunclaimednftsupply.md) | | @@ -164,5 +166,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the mint and transfer functions. | | [useNFTBalanceParams](./react.usenftbalanceparams.md) | (BETA) The params to pass to useNftBalance. | | [useTotalCirculatingSupplyParams](./react.usetotalcirculatingsupplyparams.md) | (BETA) The params to pass to useTotalCirculatingSupply. | +| [useTransferBatchNFTParams](./react.usetransferbatchnftparams.md) | (BETA) The params to pass to useTransferBatchNFT. | +| [useTransferNFTParams](./react.usetransfernftparams.md) | (BETA) The params to pass to useTransferNFT. | | [WalletAddress](./react.walletaddress.md) | (BETA) A wallet address. | diff --git a/docs/react.usetransferbatchnft.md b/docs/react.usetransferbatchnft.md new file mode 100644 index 0000000..506df02 --- /dev/null +++ b/docs/react.usetransferbatchnft.md @@ -0,0 +1,91 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferBatchNFT](./react.usetransferbatchnft.md) + +## useTransferBatchNFT() 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 transfer tokens on your + +Signature: + +```typescript +export declare function useTransferBatchNFT(contract: Erc1155): import("@tanstack/react-query").UseMutationResult Promise; +}, "data">, unknown, useTransferBatchNFTParams, unknown>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | Erc1155 | an instance of a | + +Returns: + +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [useTransferBatchNFTParams](./react.usetransferbatchnftparams.md), unknown> + +a mutation object that can be used to transfer batch NFTs + +## Example 1 + + +```jsx +const Component = () => { + const editionDrop = useEditionDrop(); + const { + mutate: transferBatchNFTs, + isLoading, + error, + } = useTransferBatchNFT(editionDrop); + + if (error) { + console.error("failed to transfer batch NFTs", error); + } + + return ( + +}; +``` + +## Example 2 + + +```jsx +const Component = () => { + const { contract } = useContract(); + const { + mutate: transferBatchNFTs, + isLoading, + error, + } = useTransferBatchNFT(contract?.nft); + + if (error) { + console.error("failed to transfer batch NFTs", error); + } + + return ( + + ); +}; +``` + diff --git a/docs/react.usetransferbatchnftparams.md b/docs/react.usetransferbatchnftparams.md new file mode 100644 index 0000000..57b5ae4 --- /dev/null +++ b/docs/react.usetransferbatchnftparams.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferBatchNFTParams](./react.usetransferbatchnftparams.md) + +## useTransferBatchNFTParams 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 `useTransferBatchNFT`. + +Signature: + +```typescript +export declare type useTransferBatchNFTParams = { + tokenId: BigNumberish; + addresses: AirdropInput; +}; +``` diff --git a/docs/react.usetransfernft.md b/docs/react.usetransfernft.md new file mode 100644 index 0000000..96edf4d --- /dev/null +++ b/docs/react.usetransfernft.md @@ -0,0 +1,86 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferNFT](./react.usetransfernft.md) + +## useTransferNFT() 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 transfer tokens on your [NFTContract](./react.nftcontract.md) + +Signature: + +```typescript +export declare function useTransferNFT(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; +}, "data">, unknown, useTransferNFTParams, unknown>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| contract | [RequiredParam](./react.requiredparam.md)<TContract> | an instance of a [NFTContract](./react.nftcontract.md) | + +Returns: + +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [useTransferNFTParams](./react.usetransfernftparams.md)<TContract>, unknown> + +a mutation object that can be used to transfer NFTs + +## Example 1 + + +```jsx +const Component = () => { + const nftDrop = useNFTDrop(); + const { + mutate: transferNFT, + isLoading, + error, + } = useTransferNFT(nftDrop); + + if (error) { + console.error("failed to transfer nft", error); + } + + return ( + + ); +}; +``` + +## Example 2 + + +```jsx +const Component = () => { + const { contract } = useContract(); + const { + mutate: transferNFT, + isLoading, + error, + } = useTransferNFT(contract?.nft); + + if (error) { + console.error("failed to transfer nft", error); + } + + return ( + + ); +}; +``` + diff --git a/docs/react.usetransfernftparams.md b/docs/react.usetransfernftparams.md new file mode 100644 index 0000000..2ac0c35 --- /dev/null +++ b/docs/react.usetransfernftparams.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferNFTParams](./react.usetransfernftparams.md) + +## useTransferNFTParams 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 `useTransferNFT`. + +Signature: + +```typescript +export declare type useTransferNFTParams = TContract extends Erc1155 ? { + to: string; + tokenId: BigNumberish; + amount: string | number; +} : { + to: string; + tokenId: BigNumberish; + amount?: never; +}; +``` diff --git a/etc/react.api.md b/etc/react.api.md index 7ec1b32..5e3c469 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -5,6 +5,7 @@ ```ts import { AbiFunction } from '@thirdweb-dev/sdk/dist/browser'; +import type { AirdropInput } from '@thirdweb-dev/sdk/dist/browser'; import type { Amount } from '@thirdweb-dev/sdk/dist/browser'; import { AuctionListing } from '@thirdweb-dev/sdk/dist/browser'; import { BaseContract } from 'ethers'; @@ -1571,9 +1572,38 @@ export type useTotalCirculatingSupplyParams = TContract extends Erc11 // @beta export function useTotalCount(contract: RequiredParam): UseQueryResult; +// @beta +export function useTransferBatchNFT(contract: Erc1155): UseMutationResult Promise; +}, "data">, unknown, useTransferBatchNFTParams, unknown>; + +// @beta +export type useTransferBatchNFTParams = { + tokenId: BigNumberish; + addresses: AirdropInput; +}; + // @beta export function useTransferBatchToken(contract: RequiredParam): UseMutationResult; +// @beta +export function useTransferNFT(contract: RequiredParam): UseMutationResult Promise; +}, "data">, unknown, useTransferNFTParams, unknown>; + +// @beta +export type useTransferNFTParams = TContract extends Erc1155 ? { + to: string; + tokenId: BigNumberish; + amount: string | number; +} : { + to: string; + tokenId: BigNumberish; + amount?: never; +}; + // @beta export function useTransferToken(contract: RequiredParam): UseMutationResult Date: Thu, 4 Aug 2022 02:51:59 +0200 Subject: [PATCH 7/9] v2.6.0-2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 938702e..a6fde6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@thirdweb-dev/react", - "version": "2.6.0-1", + "version": "2.6.0-2", "repository": { "type": "git", "url": "git+https://github.com:thirdweb-dev/react.git" From bb01f0c8bb946fa4bb97aec1143ace73609c4826 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Wed, 3 Aug 2022 19:08:52 -0700 Subject: [PATCH 8/9] rename transferbatch to airdrop --- docs/react.md | 4 +-- ...sferbatchnft.md => react.useairdropnft.md} | 26 +++++++-------- ...params.md => react.useairdropnftparams.md} | 6 ++-- etc/react.api.md | 24 +++++++------- src/hooks/async/nft.ts | 32 ++++++++++--------- src/types.ts | 2 +- 6 files changed, 48 insertions(+), 46 deletions(-) rename docs/{react.usetransferbatchnft.md => react.useairdropnft.md} (70%) rename docs/{react.usetransferbatchnftparams.md => react.useairdropnftparams.md} (72%) diff --git a/docs/react.md b/docs/react.md index c5d01e2..84eb0dd 100644 --- a/docs/react.md +++ b/docs/react.md @@ -15,6 +15,7 @@ import { useAddress } from "@thirdweb-dev/react" ``` | +| [useAirdropNFT(contract)](./react.useairdropnft.md) | (BETA) Use this to transfer tokens on your | | [useAllContractEvents(contract, options)](./react.useallcontractevents.md) | (BETA) Use this to query (and subscribe) to all events on a contract. | | [useAllRoleMembers(contract)](./react.useallrolemembers.md) | (BETA) Use this to get the roles of a | | [useAuctionWinner(contract, listingId)](./react.useauctionwinner.md) | (BETA) Use this to get the winner of an auction listing from your marketplace contract. | @@ -107,7 +108,6 @@ import { useNetworkMistmatch } from "@thirdweb-dev/react" | [useTokenSupply(contract)](./react.usetokensupply.md) | (BETA) Use this to get a the total supply of your contract. | | [useTotalCirculatingSupply(\[contract, tokenId\])](./react.usetotalcirculatingsupply.md) |

(BETA) Use this to get a the total (minted) supply of your [NFTContract](./react.nftcontract.md).

\*

| | [useTotalCount(contract)](./react.usetotalcount.md) | (BETA) Use this to get a the number of tokens in your [NFTContract](./react.nftcontract.md). | -| [useTransferBatchNFT(contract)](./react.usetransferbatchnft.md) | (BETA) Use this to transfer tokens on your | | [useTransferBatchToken(contract)](./react.usetransferbatchtoken.md) | (BETA) Use this to transfer batch tokens on your contract | | [useTransferNFT(contract)](./react.usetransfernft.md) | (BETA) Use this to transfer tokens on your [NFTContract](./react.nftcontract.md) | | [useTransferToken(contract)](./react.usetransfertoken.md) | (BETA) Use this to transfer tokens on your contract | @@ -164,9 +164,9 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [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. | | [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the mint and transfer functions. | +| [useAirdropNFTParams](./react.useairdropnftparams.md) | (BETA) The params to pass to useTransferBatchNFT. | | [useNFTBalanceParams](./react.usenftbalanceparams.md) | (BETA) The params to pass to useNftBalance. | | [useTotalCirculatingSupplyParams](./react.usetotalcirculatingsupplyparams.md) | (BETA) The params to pass to useTotalCirculatingSupply. | -| [useTransferBatchNFTParams](./react.usetransferbatchnftparams.md) | (BETA) The params to pass to useTransferBatchNFT. | | [useTransferNFTParams](./react.usetransfernftparams.md) | (BETA) The params to pass to useTransferNFT. | | [WalletAddress](./react.walletaddress.md) | (BETA) A wallet address. | diff --git a/docs/react.usetransferbatchnft.md b/docs/react.useairdropnft.md similarity index 70% rename from docs/react.usetransferbatchnft.md rename to docs/react.useairdropnft.md index 506df02..15723b9 100644 --- a/docs/react.usetransferbatchnft.md +++ b/docs/react.useairdropnft.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferBatchNFT](./react.usetransferbatchnft.md) +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useAirdropNFT](./react.useairdropnft.md) -## useTransferBatchNFT() function +## useAirdropNFT() 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. > @@ -12,10 +12,10 @@ Use this to transfer tokens on your Signature: ```typescript -export declare function useTransferBatchNFT(contract: Erc1155): import("@tanstack/react-query").UseMutationResult Promise; -}, "data">, unknown, useTransferBatchNFTParams, unknown>; +}, "data">, unknown, useAirdropNFTParams, unknown>; ``` ## Parameters @@ -26,7 +26,7 @@ export declare function useTransferBatchNFT(contract: Erc1155): import("@tanstac Returns: -import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [useTransferBatchNFTParams](./react.usetransferbatchnftparams.md), unknown> +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [useAirdropNFTParams](./react.useairdropnftparams.md), unknown> a mutation object that can be used to transfer batch NFTs @@ -37,10 +37,10 @@ a mutation object that can be used to transfer batch NFTs const Component = () => { const editionDrop = useEditionDrop(); const { - mutate: transferBatchNFTs, + mutate: airdropNFT, isLoading, error, - } = useTransferBatchNFT(editionDrop); + } = useAirdropNFT(editionDrop); if (error) { console.error("failed to transfer batch NFTs", error); @@ -49,12 +49,12 @@ const Component = () => { return ( }; ``` @@ -66,10 +66,10 @@ const Component = () => { const Component = () => { const { contract } = useContract(); const { - mutate: transferBatchNFTs, + mutate: airdropNFT, isLoading, error, - } = useTransferBatchNFT(contract?.nft); + } = useAirdropNFT(contract?.nft); if (error) { console.error("failed to transfer batch NFTs", error); @@ -78,12 +78,12 @@ const Component = () => { return ( ); }; diff --git a/docs/react.usetransferbatchnftparams.md b/docs/react.useairdropnftparams.md similarity index 72% rename from docs/react.usetransferbatchnftparams.md rename to docs/react.useairdropnftparams.md index 57b5ae4..6bf6667 100644 --- a/docs/react.usetransferbatchnftparams.md +++ b/docs/react.useairdropnftparams.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferBatchNFTParams](./react.usetransferbatchnftparams.md) +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useAirdropNFTParams](./react.useairdropnftparams.md) -## useTransferBatchNFTParams type +## useAirdropNFTParams 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. > @@ -12,7 +12,7 @@ The params to pass to `useTransferBatchNFT`. Signature: ```typescript -export declare type useTransferBatchNFTParams = { +export declare type useAirdropNFTParams = { tokenId: BigNumberish; addresses: AirdropInput; }; diff --git a/etc/react.api.md b/etc/react.api.md index 5e3c469..290ad6a 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -338,6 +338,18 @@ export function useActiveListings(contract: RequiredParam, filter?: // @public export function useAddress(): string | undefined; +// @beta +export function useAirdropNFT(contract: Erc1155): UseMutationResult Promise; +}, "data">, unknown, useAirdropNFTParams, unknown>; + +// @beta +export type useAirdropNFTParams = { + tokenId: BigNumberish; + addresses: AirdropInput; +}; + // @beta export function useAllContractEvents(contract: RequiredParam["contract"]>, options?: { queryFilter?: EventQueryFilter; @@ -1572,18 +1584,6 @@ export type useTotalCirculatingSupplyParams = TContract extends Erc11 // @beta export function useTotalCount(contract: RequiredParam): UseQueryResult; -// @beta -export function useTransferBatchNFT(contract: Erc1155): UseMutationResult Promise; -}, "data">, unknown, useTransferBatchNFTParams, unknown>; - -// @beta -export type useTransferBatchNFTParams = { - tokenId: BigNumberish; - addresses: AirdropInput; -}; - // @beta export function useTransferBatchToken(contract: RequiredParam): UseMutationResult; diff --git a/src/hooks/async/nft.ts b/src/hooks/async/nft.ts index c86e482..e25a81b 100644 --- a/src/hooks/async/nft.ts +++ b/src/hooks/async/nft.ts @@ -6,9 +6,9 @@ import { NFTContract, RequiredParam, WalletAddress, + useAirdropNFTParams, useNFTBalanceParams, useTotalCirculatingSupplyParams, - useTransferBatchNFTParams, useTransferNFTParams, } from "../../types"; import { @@ -17,9 +17,11 @@ import { } from "../../utils/cache-keys"; import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork"; import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { QueryAllParams } from "@thirdweb-dev/sdk/dist/browser"; -// eslint-disable-next-line no-duplicate-imports -import { Erc721, Erc1155 } from "@thirdweb-dev/sdk/dist/browser"; +import { + Erc721, + Erc1155, + QueryAllParams, +} from "@thirdweb-dev/sdk/dist/browser"; import { BigNumber, BigNumberish } from "ethers"; import invariant from "tiny-invariant"; @@ -526,10 +528,10 @@ export function useTransferNFT( * const Component = () => { * const editionDrop = useEditionDrop(); * const { - * mutate: transferBatchNFTs, + * mutate: airdropNFT, * isLoading, * error, - * } = useTransferBatchNFT(editionDrop); + * } = useAirdropNFT(editionDrop); * * if (error) { * console.error("failed to transfer batch NFTs", error); @@ -538,12 +540,12 @@ export function useTransferNFT( * return ( * * }; * ``` @@ -552,10 +554,10 @@ export function useTransferNFT( * const Component = () => { * const { contract } = useContract(); * const { - * mutate: transferBatchNFTs, + * mutate: airdropNFT, * isLoading, * error, - * } = useTransferBatchNFT(contract?.nft); + * } = useAirdropNFT(contract?.nft); * * if (error) { * console.error("failed to transfer batch NFTs", error); @@ -564,12 +566,12 @@ export function useTransferNFT( * return ( * * ); * }; @@ -579,14 +581,14 @@ export function useTransferNFT( * @returns a mutation object that can be used to transfer batch NFTs * @beta */ -export function useTransferBatchNFT(contract: Erc1155) { +export function useAirdropNFT(contract: Erc1155) { const activeChainId = useActiveChainId(); const contractAddress = contract?.getAddress(); const queryClient = useQueryClient(); return useMutation( - ({ tokenId, addresses }: useTransferBatchNFTParams) => { - invariant(contract?.airdrop, "contract does not support transferBatch"); + ({ tokenId, addresses }: useAirdropNFTParams) => { + invariant(contract?.airdrop, "contract does not support airdrop"); return contract.airdrop(tokenId, addresses); }, diff --git a/src/types.ts b/src/types.ts index 811dbcb..e305089 100644 --- a/src/types.ts +++ b/src/types.ts @@ -119,7 +119,7 @@ export type useTransferNFTParams = TContract extends Erc1155 * The params to pass to `useTransferBatchNFT`. * @beta */ -export type useTransferBatchNFTParams = { +export type useAirdropNFTParams = { tokenId: BigNumberish; addresses: AirdropInput; }; From ea03e233b70c0138aaa5d5cdc3d5458ca9b9e402 Mon Sep 17 00:00:00 2001 From: Jonas Daniels Date: Wed, 3 Aug 2022 19:15:43 -0700 Subject: [PATCH 9/9] fix up transfer params --- ...nftparams.md => react.airdropnftparams.md} | 6 +-- docs/react.md | 4 +- docs/react.tokenparams.md | 2 +- ...ftparams.md => react.transfernftparams.md} | 15 ++++--- docs/react.useairdropnft.md | 4 +- docs/react.usetransfernft.md | 4 +- etc/react.api.md | 43 +++++++++---------- src/hooks/async/nft.ts | 10 ++--- src/types.ts | 36 ++++++++-------- 9 files changed, 62 insertions(+), 62 deletions(-) rename docs/{react.useairdropnftparams.md => react.airdropnftparams.md} (75%) rename docs/{react.usetransfernftparams.md => react.transfernftparams.md} (59%) diff --git a/docs/react.useairdropnftparams.md b/docs/react.airdropnftparams.md similarity index 75% rename from docs/react.useairdropnftparams.md rename to docs/react.airdropnftparams.md index 6bf6667..effd8a5 100644 --- a/docs/react.useairdropnftparams.md +++ b/docs/react.airdropnftparams.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useAirdropNFTParams](./react.useairdropnftparams.md) +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [AirdropNFTParams](./react.airdropnftparams.md) -## useAirdropNFTParams type +## AirdropNFTParams 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. > @@ -12,7 +12,7 @@ The params to pass to `useTransferBatchNFT`. Signature: ```typescript -export declare type useAirdropNFTParams = { +export declare type AirdropNFTParams = { tokenId: BigNumberish; addresses: AirdropInput; }; diff --git a/docs/react.md b/docs/react.md index 84eb0dd..e8db641 100644 --- a/docs/react.md +++ b/docs/react.md @@ -150,6 +150,7 @@ import { useWalletConnect } from "@thirdweb-dev/react" | Type Alias | Description | | --- | --- | +| [AirdropNFTParams](./react.airdropnftparams.md) | (BETA) The params to pass to useTransferBatchNFT. | | [BuyNowParams](./react.buynowparams.md) | | | [ClaimIneligibilityParameters](./react.claimineligibilityparameters.md) | (BETA) The options to be passed as the second parameter to the useClaimIneligibilityReasons hook. | | [ClaimNFTParams](./react.claimnftparams.md) | (BETA) The params for the [useClaimNFT()](./react.useclaimnft.md) hook mutation. | @@ -164,9 +165,8 @@ import { useWalletConnect } from "@thirdweb-dev/react" | [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. | | [TokenParams](./react.tokenparams.md) | (BETA) The parameters to pass to the mint and transfer functions. | -| [useAirdropNFTParams](./react.useairdropnftparams.md) | (BETA) The params to pass to useTransferBatchNFT. | +| [TransferNFTParams](./react.transfernftparams.md) | (BETA) The params to pass to useTransferNFT. | | [useNFTBalanceParams](./react.usenftbalanceparams.md) | (BETA) The params to pass to useNftBalance. | | [useTotalCirculatingSupplyParams](./react.usetotalcirculatingsupplyparams.md) | (BETA) The params to pass to useTotalCirculatingSupply. | -| [useTransferNFTParams](./react.usetransfernftparams.md) | (BETA) The params to pass to useTransferNFT. | | [WalletAddress](./react.walletaddress.md) | (BETA) A wallet address. | diff --git a/docs/react.tokenparams.md b/docs/react.tokenparams.md index 0034cea..a3f5054 100644 --- a/docs/react.tokenparams.md +++ b/docs/react.tokenparams.md @@ -14,7 +14,7 @@ The parameters to pass to the mint and transfer functions. ```typescript export declare type TokenParams = { to: WalletAddress; - amount: string | number; + amount: Amount; }; ``` References: [WalletAddress](./react.walletaddress.md) diff --git a/docs/react.usetransfernftparams.md b/docs/react.transfernftparams.md similarity index 59% rename from docs/react.usetransfernftparams.md rename to docs/react.transfernftparams.md index 2ac0c35..fbe5d28 100644 --- a/docs/react.usetransfernftparams.md +++ b/docs/react.transfernftparams.md @@ -1,8 +1,8 @@ -[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [useTransferNFTParams](./react.usetransfernftparams.md) +[Home](./index.md) > [@thirdweb-dev/react](./react.md) > [TransferNFTParams](./react.transfernftparams.md) -## useTransferNFTParams type +## TransferNFTParams 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. > @@ -12,13 +12,14 @@ The params to pass to `useTransferNFT`. Signature: ```typescript -export declare type useTransferNFTParams = TContract extends Erc1155 ? { - to: string; +export declare type TransferNFTParams = TContract extends Erc1155 ? { + to: WalletAddress; tokenId: BigNumberish; - amount: string | number; + amount: Amount; } : { - to: string; + to: WalletAddress; tokenId: BigNumberish; - amount?: never; }; ``` +References: [WalletAddress](./react.walletaddress.md) + diff --git a/docs/react.useairdropnft.md b/docs/react.useairdropnft.md index 15723b9..12ab603 100644 --- a/docs/react.useairdropnft.md +++ b/docs/react.useairdropnft.md @@ -15,7 +15,7 @@ Use this to transfer tokens on your export declare function useAirdropNFT(contract: Erc1155): import("@tanstack/react-query").UseMutationResult Promise; -}, "data">, unknown, useAirdropNFTParams, unknown>; +}, "data">, unknown, AirdropNFTParams, unknown>; ``` ## Parameters @@ -26,7 +26,7 @@ export declare function useAirdropNFT(contract: Erc1155): import("@tanstack/reac Returns: -import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [useAirdropNFTParams](./react.useairdropnftparams.md), unknown> +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [AirdropNFTParams](./react.airdropnftparams.md), unknown> a mutation object that can be used to transfer batch NFTs diff --git a/docs/react.usetransfernft.md b/docs/react.usetransfernft.md index 96edf4d..2984c22 100644 --- a/docs/react.usetransfernft.md +++ b/docs/react.usetransfernft.md @@ -15,7 +15,7 @@ Use this to transfer tokens on your [NFTContract](./react.nftcontract.md) export declare function useTransferNFT(contract: RequiredParam): import("@tanstack/react-query").UseMutationResult Promise; -}, "data">, unknown, useTransferNFTParams, unknown>; +}, "data">, unknown, TransferNFTParams, unknown>; ``` ## Parameters @@ -26,7 +26,7 @@ export declare function useTransferNFT(contract: Returns: -import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [useTransferNFTParams](./react.usetransfernftparams.md)<TContract>, unknown> +import("@tanstack/react-query").UseMutationResult<Omit<{ receipt: import("@ethersproject/abstract-provider").TransactionReceipt; data: () => Promise<unknown>; }, "data">, unknown, [TransferNFTParams](./react.transfernftparams.md)<TContract>, unknown> a mutation object that can be used to transfer NFTs diff --git a/etc/react.api.md b/etc/react.api.md index 290ad6a..334448c 100644 --- a/etc/react.api.md +++ b/etc/react.api.md @@ -82,6 +82,12 @@ import type { ValidContractInstance } from '@thirdweb-dev/sdk/dist/browser'; import { Vote } from '@thirdweb-dev/sdk/dist/browser'; import { WalletConnectConnector } from 'wagmi/connectors/walletConnect'; +// @beta +export type AirdropNFTParams = { + tokenId: BigNumberish; + addresses: AirdropInput; +}; + // @public (undocumented) export type BuyNowParams = TListingType extends ListingType.Direct ? { id: BigNumberish; @@ -296,7 +302,17 @@ export interface ThirdwebSDKProviderProps extends Pick = TContract extends Erc1155 ? { + to: WalletAddress; + tokenId: BigNumberish; + amount: Amount; +} : { + to: WalletAddress; + tokenId: BigNumberish; }; export { useAccount } @@ -342,13 +358,7 @@ export function useAddress(): string | undefined; export function useAirdropNFT(contract: Erc1155): UseMutationResult Promise; -}, "data">, unknown, useAirdropNFTParams, unknown>; - -// @beta -export type useAirdropNFTParams = { - tokenId: BigNumberish; - addresses: AirdropInput; -}; +}, "data">, unknown, AirdropNFTParams, unknown>; // @beta export function useAllContractEvents(contract: RequiredParam["contract"]>, options?: { @@ -1591,18 +1601,7 @@ export function useTransferBatchToken(contract: RequiredParam): UseMutati export function useTransferNFT(contract: RequiredParam): UseMutationResult Promise; -}, "data">, unknown, useTransferNFTParams, unknown>; - -// @beta -export type useTransferNFTParams = TContract extends Erc1155 ? { - to: string; - tokenId: BigNumberish; - amount: string | number; -} : { - to: string; - tokenId: BigNumberish; - amount?: never; -}; +}, "data">, unknown, TransferNFTParams, unknown>; // @beta export function useTransferToken(contract: RequiredParam): UseMutationResult( const queryClient = useQueryClient(); return useMutation( - (data: useTransferNFTParams) => { + (data: TransferNFTParams) => { invariant(contract?.transfer, "contract does not support transfer"); if (contract instanceof Erc1155) { - invariant(data.amount, "amount not provided"); + invariant("amount" in data, "amount not provided"); return contract.transfer(data.to, data.tokenId, data.amount); } @@ -587,7 +587,7 @@ export function useAirdropNFT(contract: Erc1155) { const queryClient = useQueryClient(); return useMutation( - ({ tokenId, addresses }: useAirdropNFTParams) => { + ({ tokenId, addresses }: AirdropNFTParams) => { invariant(contract?.airdrop, "contract does not support airdrop"); return contract.airdrop(tokenId, addresses); diff --git a/src/types.ts b/src/types.ts index e305089..c9c5b9e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -41,7 +41,7 @@ export type ContractAddress = string; */ export type TokenParams = { to: WalletAddress; - amount: string | number; + amount: Amount; }; // NFTS // @@ -107,23 +107,6 @@ export type useTotalCirculatingSupplyParams = ? [contract: RequiredParam, tokenId: BigNumberish] : [contract: RequiredParam]; -/** - * The params to pass to `useTransferNFT`. - * @beta - */ -export type useTransferNFTParams = TContract extends Erc1155 - ? { to: string; tokenId: BigNumberish; amount: string | number } - : { to: string; tokenId: BigNumberish; amount?: never }; - -/** - * The params to pass to `useTransferBatchNFT`. - * @beta - */ -export type useAirdropNFTParams = { - tokenId: BigNumberish; - addresses: AirdropInput; -}; - /** * The params to pass to `useNftBalance`. * @beta @@ -139,6 +122,23 @@ export type useNFTBalanceParams = TContract extends Erc1155 ownerWalletAddress: RequiredParam, ]; +/** + * The params to pass to `useTransferNFT`. + * @beta + */ +export type TransferNFTParams = TContract extends Erc1155 + ? { to: WalletAddress; tokenId: BigNumberish; amount: Amount } + : { to: WalletAddress; tokenId: BigNumberish }; + +/** + * The params to pass to `useTransferBatchNFT`. + * @beta + */ +export type AirdropNFTParams = { + tokenId: BigNumberish; + addresses: AirdropInput; +}; + /** * The params for the {@link useMintNFT} hook mutation. *