Skip to content

Instantly share code, notes, and snippets.

@Aviksaikat
Created May 16, 2024 07:47
Show Gist options
  • Save Aviksaikat/ccec513aaf6b75846d51420f395fa07a to your computer and use it in GitHub Desktop.
Save Aviksaikat/ccec513aaf6b75846d51420f395fa07a to your computer and use it in GitHub Desktop.
get tokens associated with a token account (EOA account)
from solders.pubkey import Pubkey
from solana.rpc.api import Client
from solders.pubkey import Pubkey
from solders.keypair import Keypair
from solana.rpc.types import TokenAccountOpts
from rich.pretty import pprint
# You can use async client as well
http_client = Client("https://api.mainnet-beta.solana.com")
private_key = Keypair.from_bytes(bytes(key))
# SPL token program address: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
opts = TokenAccountOpts(program_id=Pubkey.from_string('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'))
addr = private_key.pubkey()
data = http_client.get_token_accounts_by_owner_json_parsed(addr, opts)
pprint(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment