# getCompressedTokenAccountBalance

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://solana-mainnet.g.alchemy.com/v2/{apiKey}

Returns the balance for the compressed token account with the given address or hash. Provide either `address` or `hash`.

Reference: https://www.alchemy.com/docs/chains/solana/solana-photon-api/solana-photon-api/get-compressed-token-account-balance

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| address | string or null | No | Pubkey of the compressed token account to query. |
| hash | string or null | No | Hash of the compressed token account to query. |

## Result

**Token account balance** (object): The token balance of the compressed token account.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getCompressedTokenAccountBalance",
  "params": [
    "3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "slot": 418485614
    },
    "value": {
      "amount": 108197404958
    }
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://solana-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getCompressedTokenAccountBalance",
  "params": [
    "3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL",
    "string"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getCompressedTokenAccountBalance',
    params: ['3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL', 'string']
  })
};

fetch('https://solana-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getCompressedTokenAccountBalance",
    "params": ["3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL", "string"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getCompressedTokenAccountBalance\",\n  \"params\": [\n    \"3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL\",\n    \"string\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://solana-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getCompressedTokenAccountBalance\",\n  \"params\": [\n    \"3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL\",\n    \"string\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"getCompressedTokenAccountBalance\",\n  \"params\": [\n    \"3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL\",\n    \"string\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: getCompressedTokenAccountBalance
description: Returns the balance for the compressed token account with the given address or hash. Provide either `address` or `hash`.
paramStructure: by-name
x-compute-units: 120
x-rate-limit-cus: 100
params:
  - name: address
    required: false
    description: Pubkey of the compressed token account to query.
    schema:
      oneOf:
        - title: Pubkey
          type: string
          description: Base-58 encoded public key.
        - type: 'null'
  - name: hash
    required: false
    description: Hash of the compressed token account to query.
    schema:
      oneOf:
        - title: Hash
          type: string
          description: A 32-byte hash represented as a base-58 string.
        - type: 'null'
examples:
  - name: getCompressedTokenAccountBalance example
    params:
      - name: hash
        value: 3KC9cKQhhzEPjwuyQaohM6SGaZu1ukKRZw2QRgc1sYVL
    result:
      name: Token account balance
      value:
        context:
          slot: 418485614
        value:
          amount: 108197404958
result:
  name: Token account balance
  description: The token balance of the compressed token account.
  schema:
    title: Compressed Token Account Balance Result
    type: object
    properties:
      context:
        title: Compression Context
        type: object
        properties:
          slot:
            type: integer
            description: The slot at which the response was generated.
      value:
        title: Compressed Token Account Balance
        type: object
        properties:
          amount:
            title: Unsigned Integer
            type: integer
            description: An unsigned 64-bit integer.
```
