-
Notifications
You must be signed in to change notification settings - Fork 0
/
testMetadata.js
35 lines (29 loc) · 1016 Bytes
/
testMetadata.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
const { Connection, PublicKey, clusterApiUrl } = require("@solana/web3.js");
const Metadata = require("@metaplex-foundation/mpl-token-metadata");
// Replace with your mint address (as a string).
const mintAddress = "YOUR_MINT_ADDRESS"; // Example: "So11111111111111111111111111111111111111112"
const connection = new Connection(clusterApiUrl("mainnet-beta"));
async function getMetadataPDA(mint) {
const [publicKey] = await PublicKey.findProgramAddress(
[
Buffer.from("metadata"),
Metadata.PROGRAM_ID.toBuffer(),
mint.toBuffer(),
],
Metadata.PROGRAM_ID
);
return publicKey;
}
async function fetchMetadata() {
try {
const mint = new PublicKey(mintAddress);
const pda = await getMetadataPDA(mint);
// Fetch metadata from the blockchain
const res = await Metadata.Metadata.fromAccountAddress(connection, pda);
console.log("Metadata:", res);
} catch (error) {
console.error("Error fetching metadata:", error);
}
}
// Run the test
fetchMetadata();