# getTokenSupply

The `getTokenSupply` RPC method in **CoinVera** retrieves the **total supply** of a specific SPL token mint. This method is essential for understanding the **overall quantity** of tokens created and is especially useful for token dashboards, explorers, and tokenomics tracking.

***

#### ✅ Common Use Cases

* **Displaying Token Information**\
  Show the total token supply in wallets, token explorers, or DeFi dashboards.
* **Tokenomics Analysis**\
  Understand how many tokens exist and how that relates to market cap or distribution.
* **Supply Verification**\
  Validate supply directly from the on-chain mint account for auditing or compliance.
* **Monitoring Supply Changes**\
  Detect increases or decreases in supply for mintable tokens (e.g., stablecoins or utility tokens with active minting authority).

***

#### 🧾 Request Parameters

```ts
[
  mintAddress: string,        // Required – Base-58 token mint address
  options?: {
    commitment?: string       // Optional – "processed", "confirmed", or "finalized"
  }
]
```

* **mintAddress**: The public key of the SPL token mint.
* **commitment** (optional): The network state to query against. Defaults to the node's standard (typically `finalized`).

***

#### 📦 Response Structure

The `value` field contains detailed supply information:

```json
{
  "context": { "slot": 221446650 },
  "value": {
    "amount": "500000000000",
    "decimals": 6,
    "uiAmount": 500000.0,
    "uiAmountString": "500000"
  }
}
```

* **amount**: Total supply in raw units (not adjusted for decimals).
* **decimals**: Number of decimal places defined for this token.
* **uiAmount**: Total supply as a float (may be null or imprecise).
* **uiAmountString**: Total supply as a string (accurate and display-friendly).

***

#### 🧪 Example

**Query the Supply of a Specific Token Mint**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getTokenSupply",
  "params": [
    "TokenMintAddressHere"
  ]
}
```

***

**Code Examples**

{% tabs %}
{% tab title="Nodejs" %}

```javascript
const fetch = require('node-fetch');

async function getTokenSupply(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getTokenSupply',
        "params": [
            "f68ejXhHX8M71pdnutQf8BMthpT4jJuhT7kHkdZpump",
            { "commitment": "confirmed" }
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

getTokenSupply(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def get_token_supply(rpc_url):
    try:
        response = requests.post(
            rpc_url,
            headers={
                'Content-Type': 'application/json',
            },
            json={
                'jsonrpc': '2.0',
                'id': 1,
                'method': 'getTokenSupply',
                'params': [
                    'f68ejXhHX8M71pdnutQf8BMthpT4jJuhT7kHkdZpump',
                    {'commitment': 'confirmed'}
                ]
            }
        )
        
        data = response.json()
        
        # Print the exact full response
        print('Full RPC Response:')
        print(json.dumps(data, indent=2))
        
        return data
        
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
get_token_supply(RPC_URL)
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "2.2.16",
      "slot": 355409363
    },
    "value": {
      "amount": "999999999203241",
      "decimals": 6,
      "uiAmount": 999999999.203241,
      "uiAmountString": "999999999.203241"
    }
  },
  "id": 1
}
```

***

#### 💡 Developer Tips

* **Decimals Matter**\
  Always use the `decimals` field to properly convert `amount` into a human-readable value.
* **Immutable by Default**\
  Most SPL tokens have a fixed supply unless governed by a mint authority. Track `getMint` to see if further minting is possible.
* **Prefer `uiAmountString` for Display**\
  For accurate and consistent formatting, use `uiAmountString` instead of `uiAmount`.
* **Data Source Is Direct**\
  This method reads data directly from the mint account—not from token accounts—ensuring reliable totals.
* **Burns Don’t Change Mint Supply**\
  Burning typically occurs at the token account level and does not reduce the mint’s recorded total unless explicitly programmed.

***

The `getTokenSupply` method is a vital part of working with SPL tokens, enabling reliable supply visibility for audits, analytics, and user interfaces built on **CoinVera**.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coinvera.io/integration/solana/rpc/gettokensupply.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
