-
Notifications
You must be signed in to change notification settings - Fork 94
/
index.js
53 lines (47 loc) · 1.51 KB
/
index.js
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
import Head from "next/head";
import styles from "../styles/Home.module.css";
import { Metaplex } from "@metaplex-foundation/js";
import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
import { useState } from "react";
const connection = new Connection(clusterApiUrl("devnet"));
const mx = Metaplex.make(connection);
export default function Home() {
const [address, setAddress] = useState(
"3ijFZcJKmp1EnDbbuaumWYvEFbztx9NRupwTXTchK9bP"
);
const [nft, setNft] = useState(null);
const fetchNft = async () => {
const asset = await mx.nfts().findByMint({ mintAddress: new PublicKey(address) });
setNft(asset);
};
return (
<div>
<Head>
<title>Metaplex and Next.js example</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<div className={styles.App}>
<div className={styles.container}>
<h1 className={styles.title}>NFT Mint Address</h1>
<div className={styles.nftForm}>
<input
type="text"
value={address}
onChange={(event) => setAddress(event.target.value)}
/>
<button onClick={fetchNft}>Fetch</button>
</div>
{nft && (
<div className={styles.nftPreview}>
<h1>{nft.name}</h1>
<img
src={nft.json.image}
alt="The downloaded illustration of the provided NFT address."
/>
</div>
)}
</div>
</div>
</div>
);
}