Fetching token name using token mint address with helius
Fetching token name using token mint address with helius
Loading saved threads...
frosty · External communityPost link
External question — Solana Stack Exchange
Author: frosty
Original post: https://solana.stackexchange.com/questions/21684
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am trying to programmatically fetch token name using the token mint address, upon reading other posts on here I decided to use helius, which returns a 200 status code but the metadata is empty
Code-
useEffect(()=> {
const fetchMetadata= async()=> {
if(!publicKey || !connected){
setMetadata([])
return
}
const tokenData= tokenBalance.map(async(token)=> {
try {
const response = await fetch(`https://devnet.helius-rpc.com/?api-key=${HELIUS_API_KEY}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: "test",
method: "getAsset",
params: {
id: `${token.mint}`,
}})
})
const data= await response.json();
console.log(data.result.content.metadata.name)
console.log(data.result.content.metadata.symbol)
if (data?.result?.content?.metadata){
return{
...token,
name: data.result.content.metadata.name || "unknown",
symbol: data.result.content.metadata.symbol || 'unknown'
}
}
} catch (error) {
console.log("An error has occured")
return null
}
})
const data= await Promise.all(tokenData)
const validMetadata = data.filter((item): item is TokenWithMetadata => item !== null);
setMetadata(validMetadata);
}
fetchMetadata()
API response-
{
"jsonrpc": "2.0",
"result": {
"interface": "FungibleToken",
"id": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr",
"content": {
"$schema": "https://schema.metaplex.com/nft1.0.json",
"json_uri": "",
"files": [],
"metadata": {}, // bruh
"links": {}
},
"authorities": [],
"compression": {
"eligible": false,
"compressed": false,
"data_hash": "",
"creator_hash": "",
"asset_hash": "",
"tree": "",
"seq": 0,
"leaf_id": 0
},
"grouping": [],
"royalty": {
"royalty_model": "creators",
"target": null,
"percent": 0.0,
"basis_points": 0,
"primary_sale_happened": false,
"locked": false
},
"creators": [],
"ownership": {
"frozen": false,
"delegated": false,
"delegate": null,
"ownership_model": "token",
"owner": ""
},
"supply": null,
"mutable": true,
"burnt": false,
"token_info": {
"supply": 4161587946329427697,
"decimals": 6,
"token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"mint_authority": "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr"
}
},
"id": "test"
}
Update- I Ended up finding the metadata from a solana list API, as it has a more centralised database, so if your coding something similar use helius, if it fails then use metaplex(umi method much easier, metaplex only handles onchain metadata btw) and followed by the solana API call as fallbacks before returning unknown or not found.
Quote
Report
0xp3p3x0 · External communityPost link
External answer — Solana Stack Exchange
Author: 0xp3p3x0
Original post: https://solana.stackexchange.com/a/21687
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr is not mint address.
it seems wallet address try anothre one plz,like this.
2JNdVmHaGHMxmNeF4bmY3n6RwtyezkoAToaFdqT2Xkfv
this is swift token mint address.
Quote
Report
Post Reply
Checking account access…