The Helius Digital Asset Standard (DAS) API provides powerful tools for reading and querying both NFT and token data on Solana. This guide shows you how to work with different types of Solana assets effectively.

Price Data for Jupiter Verified Tokens

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;
};

API Reference

View detailed documentation for getAsset

Response Structure

The price data is available in the response under token_info.price_info:

{
  "token_info": {
    "symbol": "Bonk",
    "supply": 8881594973561640000,
    "decimals": 5,
    "token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    "price_info": {
      "price_per_token": 0.0000192271,
      "currency": "USDC"
    }
  }
}

Calculating Market Cap

To calculate a token’s market cap, multiply its price by the adjusted supply (accounting for decimals):

const adjustedSupply = supply / Math.pow(10, decimals);
const marketCap = pricePerToken * adjustedSupply;

This calculation gives you the total market valuation of the token by properly accounting for the token’s decimal places.

Working with NFTs and Digital Collectibles

The DAS API offers several methods for working with NFTs and digital collectibles. These methods allow you to retrieve individual assets, query by owner or creator, and verify on-chain authenticity.

Getting a Single NFT

Retrieve comprehensive data for a specific 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");

Advanced NFT Query Methods

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");

Working with SPL Tokens

SPL tokens can be queried through multiple methods in the Helius API. These methods let you check balances, find token accounts, and get token metadata.

Common SPL Token Operations

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");

API Reference

View getTokenAccountBalance documentation

Advanced SPL Token Queries

You can also find all accounts holding a specific token mint:

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");

Best Practices

When working with the DAS API, keep these best practices in mind:

  1. Use pagination for methods that return large data sets
  2. Handle errors gracefully by implementing try/catch blocks
  3. Cache responses when appropriate to reduce API calls
  4. Respect rate limits to avoid disruptions in your application
  5. Verify Jupiter price data is available before calculating market cap

FAQ