Accelernate commited on
Commit
ff8e009
·
verified ·
1 Parent(s): c82f51c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from solana.rpc.async_api import AsyncClient
2
+ from solana.publickey import PublicKey
3
+ import asyncio
4
+ import requests
5
+
6
+ # The token's mint address for the desired token you want to verify
7
+ token_mint_address = "YourTokenMintAddressHere"
8
+
9
+ # Function to get all SPL token accounts for a given wallet
10
+ async def get_token_accounts(wallet_address):
11
+ async with AsyncClient("https://api.mainnet-beta.solana.com") as client:
12
+ response = await client.get_token_accounts_by_owner(PublicKey(wallet_address),
13
+ program_id=PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"))
14
+ return response['result']['value']
15
+
16
+ # Function to check if the wallet holds a specific token and amount
17
+ def verify_token_holding(token_accounts, token_mint_address, required_amount):
18
+ for account in token_accounts:
19
+ account_data = account['account']['data']['parsed']['info']
20
+ if account_data['mint'] == token_mint_address:
21
+ amount = float(account_data['tokenAmount']['uiAmount'])
22
+ if amount >= required_amount:
23
+ return True, amount
24
+ return False, 0
25
+
26
+ # Main function
27
+ async def check_wallet(wallet_address, token_mint_address, required_amount):
28
+ token_accounts = await get_token_accounts(wallet_address)
29
+ is_holding, amount = verify_token_holding(token_accounts, token_mint_address, required_amount)
30
+ if is_holding:
31
+ print(f"The wallet {wallet_address} holds at least {required_amount} of the token {token_mint_address}. It holds: {amount}")
32
+ else:
33
+ print(f"The wallet {wallet_address} does not hold the required amount of the token.")
34
+
35
+ # Prompt the user to enter their wallet address
36
+ wallet_address = input("Please enter your wallet address: ")
37
+ required_amount = float(input("Please enter the required amount: "))
38
+
39
+ # Run the check
40
+ token_mint_address = "ReplaceWithYourTokenMintAddress"
41
+ asyncio.run(check_wallet(wallet_address, token_mint_address, required_amount))
42
+
43
+ # Install required dependencies:
44
+ # pip install solana requests
45
+
46
+ """
47
+ This script is designed to check if a given Solana wallet holds a certain token and the required amount.
48
+ To use this script:
49
+ 1. Replace "ReplaceWithYourTokenMintAddress" with the actual token mint address.
50
+ 2. The script will prompt the user to paste their wallet address and required token amount.
51
+ """