Created
May 16, 2024 07:47
-
-
Save Aviksaikat/ccec513aaf6b75846d51420f395fa07a to your computer and use it in GitHub Desktop.
get tokens associated with a token account (EOA account)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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