
Buy an NFT from a primary sale
Primary sales for NFTs let you ask for the support your project needs from your community, while securely minting NFTs in return.
When your NFT sale opens, your users can buy your NFTs
Get some USDC on arbitrum sepolia to try the demo 👈Not connected
25 lines collapsed
26 const publicClient = usePublicClient();
27 const { data: walletClient } = useWalletClient();
28 const { address: userAddress } = useAccount();
29 const { openCheckoutModal } = useERC1155SaleContractCheckout({
30 chain: chainId,
31 contractAddress: salesContractAddress,
32 wallet: userAddress!,
33 collectionAddress: nftTokenAddress,
34 items: [
35 {
36 tokenId: String(tokenId),
37 quantity: String(amount),
38 },
39 ],
40 onSuccess: setSuccessfulTxHash,
41 onError: (error: Error) => {
42 console.error(error);
43 },
44 });
3 lines collapsed
48 const onClickBuy = async () => {
11 lines collapsed
60 openCheckoutModal();
61 };
62 const hasNsf =
63 userPaymentCurrencyBalance?.toString() &&
64 (userPaymentCurrencyBalance?.toString() === "0" ||
65 userPaymentCurrencyBalance < totalPrice);
66 return (
67 <>
68 <button
69 data-nsf={hasNsf}
70 className="rounded-[0.5rem] w-full font-bold text-14 data-[nsf=true]:opacity-50"
71 onClick={onClickBuy}
72 >
73 {hasNsf ? "Insufficient funds" : "Buy"}
74 </button>
75 </>
76 );