AI Agent Examples

AI Agents are autonomous programs that connect with live blockchain data, act on-chain, and automate decisions. They monitor transactions, trigger smart contracts, or provide on-chain education and support.

How They Work
  • Connect to blockchain nodes (Alchemy, Infura, etc)
  • Fetch data, monitor events, or scan for triggers
  • Use AI (OpenAI, custom ML) to analyze or decide actions
  • Act on-chain: send transactions, update contracts, rebalance wallets
  • Automate learning, risk, or compliance checks for users
Quick AI Agent Example
# Minimal AI Blockchain Agent (Python)
import openai
from web3 import Web3

openai.api_key = "YOUR_OPENAI_KEY"
web3 = Web3(Web3.HTTPProvider("https://eth-mainnet.g.alchemy.com/v2/XXX"))

def check_new_block():
    latest = web3.eth.block_number
    print("Current Ethereum Block:", latest)

def ask_ai(question):
    resp = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role":"user","content":question}]
    )
    print(resp.choices[0].message.content)

if __name__ == "__main__":
    check_new_block()
    ask_ai("What is the Ethereum Block reward?")