Pond3r API allows you to integrate AI-powered blockchain data querying capabilities directly into your applications. With our API, you can enable natural language interactions with blockchain data without requiring your users to have specialized knowledge of subgraphs, GraphQL, or protocol implementations.
from typing import Listfrom pydantic import BaseModelimport requestsfrom datetime import datetimeimport jsonclass Token(BaseModel): symbol: str amount: str or float usdValue: str or float or Noneclass LiquidationEvent(BaseModel): liquidatedUser: str liquidator: str debtToken: Token collateralToken: Token timestamp: int or str txHash: strdef get_aave_liquidations() -> List[LiquidationEvent]: request_data = { "prompt": """Get the last 10 liquidations on Aave V3 on Base. Return as JSON array with each liquidation having: - liquidatedUser (address) - liquidator (address) - debtToken: { symbol, amount, usdValue } - collateralToken: { symbol, amount, usdValue } - timestamp (unix) - txHash Response only the JSON array, nothing else. """ } response = requests.post( "https://api.pond3r.xyz/v1/messages", json=request_data, headers={ "x-api-key": "pond3r-api-key", "Content-Type": "application/json" }, timeout=60 ) response.raise_for_status() clean_response = response.json()["result"].replace("```json", "").replace("```", "") print(clean_response) return [LiquidationEvent.model_validate(item) for item in json.loads(clean_response)]def main(): try: liquidations = get_aave_liquidations() for liquidation in liquidations: print(f""" Liquidation: User: {liquidation.liquidatedUser} Debt Token: {liquidation.debtToken.amount} {liquidation.debtToken.symbol} (${float(liquidation.debtToken.usdValue):.2f}) Collateral Token: {liquidation.collateralToken.amount} {liquidation.collateralToken.symbol} (${float(liquidation.collateralToken.usdValue):.2f}) Timestamp: {datetime.fromtimestamp(liquidation.timestamp).isoformat()} Transaction: {liquidation.txHash} """) except Exception as e: print(f"Error: {str(e)}")if __name__ == "__main__": main()
These examples demonstrate how to:
Define structured schemas for Aave V3 liquidation events
Handle complex nested data structures
Format and display the results in a readable way
Maintain type safety throughout the application
You can adapt these schemas based on the specific data you’re querying from the API. The examples show a simple token price query, but the same pattern works for any structured data returned by the API.