suix_getTotalSupply - Get Total Coin Supply
Get the total supply of any coin type on Sui blockchain using Dwellir's high-performance Sui RPC infrastructure for tokenomics analysis and portfolio management.
Returns the total supply of a specified coin type on the Sui network.
Overview
The suix_getTotalSupply method provides essential information about the total supply of any coin type on Sui. This method is crucial for tokenomics analysis, market cap calculations, DeFi protocols, analytics platforms, and any application that needs to understand the monetary supply of tokens within the Sui ecosystem.
Code Examples
Common Use Cases
1. Market Cap Calculations
async function calculateMarketCap(coinType, priceUSD) {
const [supply, metadata] = await Promise.all([
getTotalSupply(coinType),
client.getCoinMetadata({ coinType })
]);
const formattedSupply = Number(supply.value) / Math.pow(10, metadata.decimals);
const marketCap = formattedSupply * priceUSD;
return {
coinType: coinType,
symbol: metadata.symbol,
supply: formattedSupply,
price: priceUSD,
marketCap: marketCap,
formattedMarketCap: `$${marketCap.toLocaleString()}`
};
}2. Tokenomics Analysis
async function analyzeTokenomics(coinType) {
const supply = await getFormattedTotalSupply(coinType);
if (!supply) return null;
// Analyze supply characteristics
const analysis = {
symbol: supply.symbol,
totalSupply: supply.formattedSupply,
supplyCategory: categorizeSupply(supply.formattedSupply),
inflationRisk: assessInflationRisk(supply.formattedSupply),
liquidityIndicator: calculateLiquidityIndicator(supply.formattedSupply),
scarcityScore: calculateScarcityScore(supply.formattedSupply)
};
return analysis;
}
function categorizeSupply(supply) {
if (supply >= 1_000_000_000_000) return 'Ultra High Supply';
if (supply >= 100_000_000_000) return 'Very High Supply';
if (supply >= 1_000_000_000) return 'High Supply';
if (supply >= 100_000_000) return 'Medium-High Supply';
if (supply >= 1_000_000) return 'Medium Supply';
if (supply >= 100_000) return 'Low-Medium Supply';
if (supply >= 10_000) return 'Low Supply';
return 'Very Low Supply';
}3. DeFi Protocol Monitoring
async function monitorProtocolSupplies(protocolTokens, callback) {
const tracker = new SupplyTracker(client);
setInterval(async () => {
const changes = await tracker.trackMultipleSupplies(protocolTokens);
const significantChanges = Object.entries(changes).filter(
([, change]) => Math.abs(Number(change.absoluteChange)) > 0
);
if (significantChanges.length > 0) {
callback({
timestamp: new Date().toISOString(),
changes: significantChanges.map(([coinType, change]) => ({
coinType,
change: change.absoluteChange,
percentage: change.percentageChange
}))
});
}
}, 30000); // Check every 30 seconds
}4. Portfolio Value Calculator
async function calculatePortfolioValue(holdings, prices) {
const totalValue = {
totalUSD: 0,
breakdown: []
};
for (const holding of holdings) {
const supply = await getFormattedTotalSupply(holding.coinType);
const price = prices[holding.coinType] || 0;
if (supply && price > 0) {
const holdingPercentage = Number(holding.balance) /
Math.pow(10, supply.decimals) / supply.formattedSupply * 100;
const holdingValue = (Number(holding.balance) /
Math.pow(10, supply.decimals)) * price;
totalValue.breakdown.push({
symbol: supply.symbol,
holdings: Number(holding.balance) / Math.pow(10, supply.decimals),
percentage: holdingPercentage,
value: holdingValue,
totalSupply: supply.formattedSupply
});
totalValue.totalUSD += holdingValue;
}
}
return totalValue;
}Best Practices
1. Supply Data Caching
// Cache supply data with reasonable TTL since it changes infrequently
const supplyCache = new Map();
const SUPPLY_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
async function getCachedTotalSupply(coinType) {
const cached = supplyCache.get(coinType);
if (cached && Date.now() - cached.timestamp < SUPPLY_CACHE_TTL) {
return cached.data;
}
const supply = await getTotalSupply(coinType);
if (supply) {
supplyCache.set(coinType, {
data: supply,
timestamp: Date.now()
});
}
return supply;
}2. Precision Handling
// Use BigInt for precise supply calculations
function calculateSupplyRatio(supply1, supply2) {
const s1 = BigInt(supply1);
const s2 = BigInt(supply2);
if (s2 === BigInt(0)) return null;
// Calculate ratio with high precision
const ratio = (s1 * BigInt(10000)) / s2; // 4 decimal places
return Number(ratio) / 10000;
}3. Error Handling
async function safeGetTotalSupply(coinType) {
try {
const supply = await getTotalSupply(coinType);
if (!supply || !supply.value) {
return {
success: false,
error: 'No supply data available'
};
}
return {
success: true,
data: supply
};
} catch (error) {
return {
success: false,
error: error.message,
retry: !error.message.includes('not found')
};
}
}Supply Interpretation
Understanding Supply Values
- Raw Values: Always returned in smallest unit (e.g., MIST for SUI)
- Total Supply vs Off-Chain Float: This method returns total supply
- Burned Tokens: Burned tokens are automatically subtracted from supply
- Minting Events: New minting increases the total supply immediately
Supply Categories
- Deflationary: Supply decreases over time through burning
- Inflationary: Supply increases through ongoing minting
- Fixed: Supply is capped and cannot increase
- Elastic: Supply adjusts based on market conditions
Related Methods
- suix_getCoinMetadata - Get coin metadata for formatting
- suix_getBalance - Query individual balances
- suix_getCoins - Get coin objects
Notes
- Supply can change due to minting, burning, or staking operations
- Values are real-time and reflect the current blockchain state
- Use metadata to properly format supply values for display
- Large numbers may require BigInt handling in JavaScript
- Monitor changes for tokens with dynamic supply models
Need help? Contact our support team or check the Sui documentation.
suix_getStakes - Get Staking Info
Get comprehensive staking information for addresses on Sui blockchain. Query staking positions, rewards, and delegation details with Dwellir's high-performance Sui RPC infrastructure.
suix_getValidatorsApy - Get Validator AP...
Get detailed validator APY (Annual Percentage Yield) information for staking rewards on Sui blockchain using Dwellir's high-performance Sui RPC infrastructure.