Tracking Ethereum transaction status can be tricky, especially when you want reliable, real-time updates. Using the Crypto API Service, you can easily check if a transaction is pending, confirmed, or failed.
In this tutorial, we’ll create a Python async script to query the transaction status of an Ethereum transaction using the API.
1️⃣ Setup
- Python 3.11+
- Install dependencies:
pip install httpx asyncio
- RapidAPI key (subscribe to Crypto API Service)
2️⃣ Example Python Script
Create check_eth_tx.py:
# check_eth_tx.py
import asyncio
import httpx
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
API_URL = "https://api.aigoretech.cloud/api/v1/crypto/tx_status"
API_KEY = "YOUR_RAPIDAPI_KEY" # replace with your RapidAPI key
async def get_tx_status(tx_hash: str):
"""Async function to fetch Ethereum transaction status"""
async with httpx.AsyncClient() as client:
try:
resp = await client.get(
API_URL,
params={"chain": "eth", "tx_hash": tx_hash},
headers={"X-RapidAPI-Key": API_KEY}
)
resp.raise_for_status()
data = resp.json()
logger.info(f"Transaction data: {data}")
return data
except httpx.HTTPError as e:
logger.error(f"Failed to fetch transaction: {e}")
return None
async def main():
tx_hash = "0x123abc...your_tx_hash_here"
tx_data = await get_tx_status(tx_hash)
if tx_data:
print(f"Transaction Hash: {tx_data['tx_hash']}")
print(f"Status: {tx_data['status']}")
print(f"Message: {tx_data.get('message', '')}")
if __name__ == "__main__":
asyncio.run(main())
3️⃣ Example Output
{
"status": "confirmed",
"tx_hash": "0x123abc...your_tx_hash_here",
"message": "Transaction successfully processed"
}
Console output:
Transaction Hash: 0x123abc...your_tx_hash_here
Status: confirmed
Message: Transaction successfully processed
4️⃣ How to Run
- Save script as
check_eth_tx.py - Replace
YOUR_RAPIDAPI_KEYwith your RapidAPI key - Run:
python check_eth_tx.py
- Check console to see the status of your Ethereum transaction
5️⃣ Closing
With this script, you can quickly check Ethereum transaction status without running your own node or relying on multiple providers.
This is perfect for wallets, dApps, or monitoring tools. Explore more endpoints like balance or token transfers using the Crypto API Service on RapidAPI.
Suggested Tags
python, fastapi, crypto, ethereum, api, tutorial
Top comments (0)