Shred Delivery and Sender are now live! Get earliest access to raw Solana data and optimized transaction sending. Learn about Shred Delivery | Learn about Sender
简体中文
学习如何使用 Helius DAS API 检索和查询 Solana NFTs、SPL 代币和价格数据。完整指南包括代码示例和最佳实践。
const fetchTokenPriceData = async () => { const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ jsonrpc: "2.0", id: "1", method: "getAsset", params: { id: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263", // Bonk token mint address displayOptions: { showFungibleTokens: true } }, }), }); const data = await response.json(); // Calculate market cap if (data.result?.token_info?.price_info) { const { price_per_token } = data.result.token_info.price_info; const { supply, decimals } = data.result.token_info; // Adjust supply for decimals const adjustedSupply = supply / Math.pow(10, decimals); const marketCap = price_per_token * adjustedSupply; console.log(`Market Cap: ${marketCap.toLocaleString()}`); } return data; };
token_info.price_info
{ "token_info": { "symbol": "Bonk", "supply": 8881594973561640000, "decimals": 5, "token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", "price_info": { "price_per_token": 0.0000192271, "currency": "USDC" } } }
const adjustedSupply = supply / Math.pow(10, decimals); const marketCap = pricePerToken * adjustedSupply;
检索特定NFT的综合数据:
const getNFT = async (mintAddress) => { const response = await fetch('https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY', { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ jsonrpc: "2.0", id: "1", method: "getAsset", params: { id: mintAddress, }, }), }); const data = await response.json(); return data; }; // Example usage getNFT("F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk");
const getAssetsByCreator = async (creatorAddress) => { const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ jsonrpc: "2.0", id: "1", method: "getAssetsByCreator", params: { creatorAddress: creatorAddress, page: 1, limit: 100, }, }), }); const data = await response.json(); return data; }; // Example usage getAssetsByCreator("9uBX3ASjxWvNBAD1xjbVaKA74mWGZys3RGSF7DdeDD3F");
const getTokenBalance = async (tokenAccountAddress) => { const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: '1', method: 'getTokenAccountBalance', params: [tokenAccountAddress] }) }); const data = await response.json(); return data; }; // Example usage getTokenBalance("3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa");
const getTokenAccountsByMint = async (mintAddress) => { const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: '1', method: 'getTokenAccountsByOwner', params: [ 'CEXq1uy9y15PL2Wb4vDQwQfcJakBGjaAjeuR2nKLj8dk', // Owner address { mint: mintAddress }, { encoding: 'jsonParsed' } ] }) }); const data = await response.json(); return data; }; // Example usage getTokenAccountsByMint("8wXtPeU6557ETkp9WHFY1n1EcU6NxDvbAggHGsMYiHsB");
此页面对您有帮助吗?