Hook for granting approval to NiftyApes to be able to access all NFTs you own in a collection. This hook automatically checks if permission has been granted already.
import { useERC721SetApprovalForAll } from "@niftyapes/sdk";
Usage
import React from "react";
import { useERC721SetApprovalForAll } from "@niftyapes/sdk";
import { useWaitForTransaction } from "wagmi";
const UseERC721SetApprovalForAll: React.FC = () => {
const nftContractAddress = "0xa608475ec077e10d71db7476745d85f9e860e540";
const { hasCheckedApprovalForAll, hasApprovalForAll, write, data } =
useERC721SetApprovalForAll({ nftContractAddress });
const approvalRequired = hasCheckedApprovalForAll && !hasApprovalForAll;
const {
isLoading: isApproving,
isSuccess: isApproved,
isError,
} = useWaitForTransaction({ hash: data?.hash });
return (
<div>
<div>
{approvalRequired && (
<button onClick={() => write?.()}>
Approve Transfer for All Tokens
</button>
)}
</div>
<div>{isApproving && "Approving"}</div>
<div>{isApproved && "Transfer Approved"}</div>
<div>{isError && "Usable to approve transfer at this time"}</div>
</div>
);
};
export default UseERC721SetApprovalForAll;
Configuration
Requires a valid collection contract address.
{
nftContractAddress: Address;
}
Return Value
{
approvalCheckErr: boolean,
hasCheckedApprovalForAll: boolean,
hasApprovalForAll: boolean,
data?: TransactionResponse,
error?: Error,
isError: boolean,
isIdle: boolean,
isLoading: boolean,
isSuccess: boolean,
status: 'idle' | 'error' | 'loading' | 'success',
write?: () => void,
}