 
 
import json

import requests

url = "https://solana-mainnet.g.alchemy.com/v2/pxF-cEkEE1JxzxgotGyww5ra5w1IvAkJ"
str_dalao_address = ""
getBalance_payload = {
  
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getBalance",
    "params": [ "318jS2NM4QC5nsD8Y7BoYBLpRcPDXtic1Wc8xs6MDfDg" ]
}
 
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}
 
 
getTransaction_payload = {
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getTransaction",
    "params": ["28qc2NVfCJgmSvNBFHVPiMXjQzufXEFR2QpWU928ab2QvvBVL7tdX4xJBTJdLmsbqfikhxbcMWzXCqK5E9rGqBvL",  
                {
            "maxSupportedTransactionVersion": 0,
            "commitment": "confirmed"
        }]
}
 
response = requests.post(url, json=getTransaction_payload, headers=headers)
response = json.loads(
response.text)
response_result = response["result"]
 
 

 
with open("response_result.json",mode='w') as f:
    json.dump(response_result,f)
 
str_dalao_address =  "HTVupcGHvA8tXX5pHmmAxQ8eiFAJSJhYNQjer3zycLcU"
str_token_address = "Cu7NAWTDK4dAFjrycPNDqTcHwXXB57onxvA7D9zQpump"
print(response_result)


arr_postTokenBalances = response_result["meta"]["postTokenBalances"]
arr_preTokenBalances = response_result["meta"]["preTokenBalances"]

arr_postTokenBalances=[obj for obj in arr_postTokenBalances if (obj["owner"]==str_dalao_address and obj["mint"]==str_token_address )]

arr_preTokenBalances=[obj for obj in arr_preTokenBalances if (obj["owner"]==str_dalao_address and obj["mint"]==str_token_address )]

if( len(arr_postTokenBalances)>1 or  len(arr_preTokenBalances)>1 ):
    print("arr_TokenBalances_len>1")
    raise

number_dalao_postTokenBalance = 0
number_dalao_perTokenBalance = 0

if len(arr_preTokenBalances)!=0:
    number_dalao_perTokenBalance = arr_preTokenBalances[0]["uiTokenAmount"]["uiAmount"]

if len(arr_postTokenBalances)!=0:
    number_dalao_postTokenBalance = arr_postTokenBalances[0]["uiTokenAmount"]["uiAmount"]


number_dalao_TokenBalance_change = number_dalao_postTokenBalance - number_dalao_perTokenBalance

print("number_dalao_TokenBalance_change=",number_dalao_TokenBalance_change)