-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (44 loc) · 1.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
def get_token_mint_addresses(wallet_address):
# Solana JSON RPC API endpoint
endpoint = "https://api.mainnet-beta.solana.com"
# Request payload to get token accounts by owner
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "getTokenAccountsByOwner",
"params": [
wallet_address,
{
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"encoding": "jsonParsed"
}
]
}
# Make the HTTP request
response = requests.post(endpoint, json=payload)
response_data = response.json()
# Check if the response contains any result
if "result" in response_data:
token_accounts = response_data["result"]["value"]
# Extract the mint addresses
mint_addresses = []
for account in token_accounts:
if "account" in account and "data" in account["account"]:
mint_address = account["account"]["data"]["parsed"]["info"]["mint"]
mint_addresses.append(mint_address)
return mint_addresses
else:
raise Exception("Error fetching token accounts")
# Wallet address for which to get token mint addresses
wallet_address = "39azUYFWPz3VHgKCf3VChUwbpURdCHRxjWVowf5jUJjg"
# Get token mint addresses
try:
mint_addresses = get_token_mint_addresses(wallet_address)
print(f"Mint addresses of tokens created by wallet {wallet_address}:")
for address in mint_addresses:
print(address)
except Exception as e:
print(e)