Skip to content

Instantly share code, notes, and snippets.

@de7215
Created April 10, 2024 18:46
Show Gist options
  • Select an option

  • Save de7215/49b086acaf83623e804c3bd197c864b1 to your computer and use it in GitHub Desktop.

Select an option

Save de7215/49b086acaf83623e804c3bd197c864b1 to your computer and use it in GitHub Desktop.
Solana Account Priority Fee Estimator: A Python script to fetch priority fee estimates for Solana accounts using the Helius RPC API.
from typing import Optional, Dict
import requests
import json
from utils import get_helius_api_key
ORE_ACCOUNTS = {
"BUS0": "9ShaCzHhQNvH8PLfGyrJbB8MeKHrDnuPMLnUDLJ2yMvz",
"BUS1": "4Cq8685h9GwsaD5ppPsrtfcsk3fum8f9UP4SPpKSbj2B",
"BUS2": "8L1vdGdvU3cPj9tsjJrKVUoBeXYvAzJYhExjTYHZT7h7",
"BUS3": "JBdVURCrUiHp4kr7srYtXbB7B4CwurUt1Bfxrxw6EoRY",
"BUS4": "DkmVBWJ4CLKb3pPHoSwYC2wRZXKKXLD2Ued5cGNpkWmr",
"BUS5": "9uLpj2ZCMqN6Yo1vV6yTkP6dDiTTXmeM5K3915q5CHyh",
"BUS6": "EpcfjBs8eQ4unSMdowxyTE8K3vVJ3XUnEr5BEWvSX7RB",
"BUS7": "Ay5N9vKS2Tyo2M9u9TFt59N1XbxdW93C7UrFZW3h8sMC",
"TREASURE": "FTap9fv2GPpWGqrLj3o4c9nHH7p36ih7NbSWHnrkQYqa",
"MINT": "oreoN2tQbHXVaZsr3pf66A48miqcBXCDJozganhEJgz"
}
def get_account_priority_fee(account: str) -> Optional[Dict]:
"""
Fetches the priority fee estimate for a given Solana account from the Helius RPC API.
Parameters:
account (str): The Solana account public key for which to get the priority fee estimate.
Returns:
Optional[Dict]: A dictionary containing the priority fee estimate if successful, None otherwise.
"""
payload = {
"jsonrpc": "2.0",
"id": "1",
"method": "getPriorityFeeEstimate",
"params": [{
"accountKeys": [account],
"options": {
"includeAllPriorityFeeLevels": True,
"lookback_slots": 1000,
}
}]
}
url = f"https://mainnet.helius-rpc.com/?api-key={get_helius_api_key()}"
try:
response = requests.post(url, json=payload)
response.raise_for_status()
return response.json()
except requests.RequestException as e:
print(f"HTTP Error: {e}")
return None
def main():
result = {}
for token, mint in ORE_ACCOUNTS.items():
res = get_account_priority_fee(mint)
if res:
res["account"] = mint
result[token] = res
else:
print(f"Failed to fetch data for token: {token}, mint: {mint}")
print(json.dumps(result, indent=4))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment