This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.ts
56 lines (47 loc) · 1.38 KB
/
index.ts
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
import { decodeMetadata } from './utils'
import { PublicKey } from '@solana/web3.js'
import 'isomorphic-fetch';
const METADATA_PUBKEY = new PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
const get_metadataPda = async (address:PublicKey) => {
let [pda, bump] = await PublicKey.findProgramAddress([
Buffer.from("metadata"),
METADATA_PUBKEY.toBuffer(),
address.toBuffer(),
], METADATA_PUBKEY)
return pda
}
async function getTokenMetadata(token_address:string) {
try {
const token_publickey = new PublicKey(token_address)
const metadata_pda = await get_metadataPda(token_publickey);
const data = {
"jsonrpc": "2.0",
"id": 1,
"method": "getAccountInfo",
"params": [
metadata_pda.toBase58(),
{
"encoding": "base64"
}
]
}
const metadata_res = await fetch("https://api.mainnet-beta.solana.com", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
});
const metadata_parsed = await metadata_res.json();
const metadata_buf = Buffer.from(metadata_parsed.result.value.data[0], 'base64');
const metadata = decodeMetadata(metadata_buf)
console.log(metadata)
const arweave_res = await fetch(metadata.data.uri)
const arweave= await arweave_res.json()
console.log("Arweave ",arweave)
return { metadata ,arweave}
} catch (e) {
console.log(e)
}
}
getTokenMetadata(process.argv[2])