Junaidb commited on
Commit
d5fa359
·
verified ·
1 Parent(s): 86a0494

Update components/checktoken.py

Browse files
Files changed (1) hide show
  1. components/checktoken.py +14 -36
components/checktoken.py CHANGED
@@ -1,12 +1,8 @@
1
- import requests
2
-
3
-
4
- def TokenCheck(address):
5
-
6
-
7
 
 
8
 
9
- url = f"https://mainnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b"
10
  payload = {
11
  "jsonrpc": "2.0",
12
  "id": "1",
@@ -15,45 +11,27 @@ def TokenCheck(address):
15
  address,
16
  {"mint": "3d4XyPWkUJzruF5c2qc1QfpLgsaNaDLMtTya1bWBpump"},
17
  {"encoding": "jsonParsed"}
18
- ]
19
  }
20
-
21
- headers = {"Content-Type": "application/json"}
22
-
23
  try:
24
- response = requests.post(url, json=payload, headers=headers)
25
- response.raise_for_status()
26
- data = response.json()
27
-
28
- except requests.exceptions.RequestException as e:
29
-
30
  return False
31
 
32
-
33
  token_accounts = data.get("result", {}).get("value")
34
 
35
-
36
  if not token_accounts:
37
-
38
  return False
39
-
40
-
41
  try:
42
  account_info = token_accounts[0]["account"]["data"]["parsed"]["info"]
43
  token_amount = account_info["tokenAmount"]
44
  ui_amount = float(token_amount.get("uiAmount"))
45
-
46
- except (TypeError, KeyError, IndexError):
47
-
48
- return {"status": False, "message": "Could not parse token account data"}
49
-
50
-
51
- if int(ui_amount) >= required_mint:
52
-
53
- return True
54
-
55
- else:
56
  return False
57
-
58
-
59
-
 
1
+ import httpx
 
 
 
 
 
2
 
3
+ async def TokenCheck(address):
4
 
5
+ url = "https://mainnet.helius-rpc.com/?api-key=4e833ada-d32c-48c5-b020-c11b2253f25b"
6
  payload = {
7
  "jsonrpc": "2.0",
8
  "id": "1",
 
11
  address,
12
  {"mint": "3d4XyPWkUJzruF5c2qc1QfpLgsaNaDLMtTya1bWBpump"},
13
  {"encoding": "jsonParsed"}
14
+ ],
15
  }
16
+
 
 
17
  try:
18
+ async with httpx.AsyncClient() as client:
19
+ response = await client.post(url, json=payload)
20
+ response.raise_for_status()
21
+ data = response.json()
22
+ except Exception:
 
23
  return False
24
 
 
25
  token_accounts = data.get("result", {}).get("value")
26
 
 
27
  if not token_accounts:
 
28
  return False
29
+
 
30
  try:
31
  account_info = token_accounts[0]["account"]["data"]["parsed"]["info"]
32
  token_amount = account_info["tokenAmount"]
33
  ui_amount = float(token_amount.get("uiAmount"))
34
+ except:
 
 
 
 
 
 
 
 
 
 
35
  return False
36
+
37
+ return ui_amount >= required_mint