---
title: How to Get All Token Accounts by Authority
description:
  "Learn how to retrieve Solana token accounts by owner, including all accounts
  or filtered by mint."
---

You can fetch token accounts by owner. There are two ways to do it.

1. Get All Token Account

<CodeTabs storage="cookbook" flags="r">

```ts !! title="Kit" file=packages/docs-examples/cookbook/tokens/get-all-token-accounts/all-kit.ts#region=all

```

```typescript !! title="Legacy" file=packages/docs-examples/cookbook/tokens/get-all-token-accounts/all-legacy.ts#region=all

```

```rust !! title="Rust" file=packages/docs-examples/cookbook/tokens/get-all-token-accounts/rust/src/bin/all.rs#region=all

```

</CodeTabs>

2. Filter By Mint

<CodeTabs storage="cookbook" flags="r">

```ts !! title="Kit" file=packages/docs-examples/cookbook/tokens/get-all-token-accounts/by-mint-kit.ts#region=by-mint

```

```typescript !! title="Legacy" file=packages/docs-examples/cookbook/tokens/get-all-token-accounts/by-mint-legacy.ts#region=by-mint

```

```rust !! title="Rust" file=packages/docs-examples/cookbook/tokens/get-all-token-accounts/rust/src/bin/by-mint.rs#region=by-mint

```

```py !! title="Python"
#!/usr/bin/env python3
"""
Solana Cookbook - How to Get All Token Accounts by Owner
"""

import asyncio
from solana.rpc.async_api import AsyncClient
from solders.pubkey import Pubkey
from spl.token.constants import TOKEN_PROGRAM_ID
from solana.rpc.types import TokenAccountOpts

async def main():
    rpc = AsyncClient("http://localhost:8899")

    # Example owner address
    owner = Pubkey.from_string("4kg8oh3jdNtn7j2wcS7TrUua31AgbLzDVkBZgTAe44aF")

    async with rpc:
        try:
            # Get all token accounts by owner
            response = await rpc.get_token_accounts_by_owner(
                owner,
                TokenAccountOpts(program_id=TOKEN_PROGRAM_ID)
            )

            print(f"Owner: {owner}")
            print(f"Found {len(response.value)} token accounts:\n")

            for account_info in response.value:
                print(f"Pubkey: {account_info.pubkey}")
                print(f"Owner: {account_info.account.owner}")
                print(f"Lamports: {account_info.account.lamports}")
                print(f"Data Length: {len(account_info.account.data)} bytes")
                print("=" * 50)

        except Exception as e:
            print(f"Error getting token accounts: {e}")

if __name__ == "__main__":
    asyncio.run(main())
```

</CodeTabs>
