# getBalanceByOwnerAtSlot

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

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

Returns a wallet's total balance of a single SPL Token or Token-2022 mint as of a specific slot, already summed across every token account the wallet held of that mint. It returns a single figure rather than the list of accounts returned by `getTokenAccountsByOwnerAtSlot`.

A wallet can own more than one token account for the same mint. The optional `scope` parameter selects which of them the result covers: `all` (default) sums every token account the wallet held of that mint at that slot, `ata` returns the balance of the wallet's canonical Associated Token Account only (derived from `(wallet, token program, mint)`, with the token program selected from the mint so Token-2022 mints resolve correctly). When a wallet holds exactly one token account of the mint, both scopes return the same value.

Available on Solana mainnet only. The request may also be sent as a positional array `[wallet, mint, slot, scope]`, and `owner` is accepted as an alias for `wallet`.

Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/get-balance-by-owner-at-slot

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| wallet | string | Yes | Base-58 encoded pubkey of the wallet whose balance you want. `owner` is accepted as an alias. |
| mint | string | Yes | Base-58 encoded pubkey of the token mint. SPL Token and Token-2022 mints are both supported. |
| slot | integer | Yes | The slot to reconstruct the balance at. There is no "latest slot" default; omitting `slot` is an error. |
| scope | enum | No | Which of the wallet's token accounts the balance covers. `all` (default) sums every token account the wallet held of that mint at that slot; `ata` returns the balance of the wallet's canonical Associated Token Account only. Case-sensitive. |

## Result

**Balance at slot** (object): The wallet's total token balance for that mint at the requested slot, with the slot the balance was computed at.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "getBalanceByOwnerAtSlot",
  "params": [
    "FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR",
    "poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk",
    225000000
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "wallet": "FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR",
    "mint": "poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk",
    "isNative": false,
    "balance": "38205.4",
    "balanceRaw": "3820540000000",
    "decimals": 8,
    "slot": 225000000
  },
  "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": "getBalanceByOwnerAtSlot",
  "params": [
    "FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR",
    "poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk",
    225000000,
    "all"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getBalanceByOwnerAtSlot',
    params: [
      'FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR',
      'poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk',
      225000000,
      'all'
    ]
  })
};

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": "getBalanceByOwnerAtSlot",
    "params": ["FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR", "poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk", 225000000, "all"]
}
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\": \"getBalanceByOwnerAtSlot\",\n  \"params\": [\n    \"FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR\",\n    \"poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk\",\n    225000000,\n    \"all\"\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\": \"getBalanceByOwnerAtSlot\",\n  \"params\": [\n    \"FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR\",\n    \"poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk\",\n    225000000,\n    \"all\"\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\": \"getBalanceByOwnerAtSlot\",\n  \"params\": [\n    \"FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR\",\n    \"poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk\",\n    225000000,\n    \"all\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: getBalanceByOwnerAtSlot
summary: Returns a wallet's total balance of a single SPL Token or Token-2022 mint as of a specific slot.
description: |-
  Returns a wallet's total balance of a single SPL Token or Token-2022 mint as of a specific slot, already summed across every token account the wallet held of that mint. It returns a single figure rather than the list of accounts returned by `getTokenAccountsByOwnerAtSlot`.

  A wallet can own more than one token account for the same mint. The optional `scope` parameter selects which of them the result covers: `all` (default) sums every token account the wallet held of that mint at that slot, `ata` returns the balance of the wallet's canonical Associated Token Account only (derived from `(wallet, token program, mint)`, with the token program selected from the mint so Token-2022 mints resolve correctly). When a wallet holds exactly one token account of the mint, both scopes return the same value.

  Available on Solana mainnet only. The request may also be sent as a positional array `[wallet, mint, slot, scope]`, and `owner` is accepted as an alias for `wallet`.
x-compute-units: 40
paramStructure: by-name
params:
  - name: wallet
    required: true
    description: Base-58 encoded pubkey of the wallet whose balance you want. `owner` is accepted as an alias.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: mint
    required: true
    description: Base-58 encoded pubkey of the token mint. SPL Token and Token-2022 mints are both supported.
    schema:
      title: Pubkey
      type: string
      description: Base-58 encoded public key.
  - name: slot
    required: true
    description: The slot to reconstruct the balance at. There is no "latest slot" default; omitting `slot` is an error.
    schema:
      type: integer
      minimum: 0
  - name: scope
    required: false
    description: Which of the wallet's token accounts the balance covers. `all` (default) sums every token account the wallet held of that mint at that slot; `ata` returns the balance of the wallet's canonical Associated Token Account only. Case-sensitive.
    schema:
      type: string
      enum:
        - all
        - ata
      default: all
examples:
  - name: getBalanceByOwnerAtSlot example
    params:
      - name: wallet
        value: FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR
      - name: mint
        value: poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk
      - name: slot
        value: 225000000
    result:
      name: Balance at slot
      value:
        wallet: FHX9fPAUVA1MxPme28f4eeVH81QVRHDWofa2V6FUJaiR
        mint: poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk
        isNative: false
        balance: '38205.4'
        balanceRaw: '3820540000000'
        decimals: 8
        slot: 225000000
result:
  name: Balance at slot
  description: The wallet's total token balance for that mint at the requested slot, with the slot the balance was computed at.
  schema:
    title: GetBalanceByOwnerAtSlot Result
    type: object
    description: A wallet's aggregated balance of a single SPL Token or Token-2022 mint at the requested slot. The response shape is identical for every `scope`, so callers never need to branch.
    properties:
      wallet:
        title: Pubkey
        type: string
        description: The wallet queried.
      mint:
        title: Pubkey
        type: string
        description: The token mint queried.
      isNative:
        type: boolean
        description: '`true` for Wrapped SOL, otherwise `false`.'
      balance:
        type: string
        description: Human-readable amount (`balanceRaw` scaled by `decimals`). Returned as a string so large values survive JSON parsing without precision loss.
      balanceRaw:
        type: string
        description: Raw token amount, as an integer string. Parse as a big integer, not a float.
      decimals:
        type: integer
        description: Mint decimals.
      slot:
        type: integer
        description: The slot the balance was computed at.
errors:
  - code: -32602
    message: Invalid params. Common causes include a missing or malformed `wallet` / `mint` (each must be a 32-byte base58 pubkey), a missing or non-integer `slot`, an unknown `scope` value (only `all` and `ata` are accepted, case-sensitive), or a mint that is not present in the index.
  - code: -32600
    message: Unsupported method. Returned when the method is called against a chain other than Solana mainnet.
  - code: -32603
    message: Internal error. Retry the request; if it persists, contact support.
```
