forked from thirdweb-example/nft-staking-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmint.tsx
60 lines (52 loc) · 1.63 KB
/
mint.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { useAddress, useMetamask, useNFTDrop } from "@thirdweb-dev/react";
import type { NextPage } from "next";
import { useRouter } from "next/router";
import styles from "../styles/Home.module.css";
const Mint: NextPage = () => {
const router = useRouter();
// Get the currently connected wallet's address
const address = useAddress();
// Function to connect to the user's Metamask wallet
const connectWithMetamask = useMetamask();
// Get the NFT Collection contract
const nftDropContract = useNFTDrop(
"0x322067594DBCE69A9a9711BC393440aA5e3Aaca1"
);
async function claimNft() {
try {
const tx = await nftDropContract?.claim(1);
console.log(tx);
alert("NFT Claimed!");
router.push(`/stake`);
} catch (error) {
console.error(error);
alert(error);
}
}
return (
<div className={styles.container}>
<h1 className={styles.h1}>Mint An NFT!</h1>
<p className={styles.explain}>
Here is where we use our <b>NFT Drop</b> contract to allow users to mint
one of the NFTs that we lazy minted.
</p>
<hr className={`${styles.smallDivider} ${styles.detailPageHr}`} />
{!address ? (
<button
className={`${styles.mainButton} ${styles.spacerBottom}`}
onClick={connectWithMetamask}
>
Connect Wallet
</button>
) : (
<button
className={`${styles.mainButton} ${styles.spacerBottom}`}
onClick={() => claimNft()}
>
Claim An NFT
</button>
)}
</div>
);
};
export default Mint;