Skip to main content

Open-source framework for building autonomous AI agents that interact with blockchain networks

Project description

๐Ÿค– Web3 Agent Kit

Open-source framework for building autonomous AI agents that interact with blockchain networks.

License: MIT Python 3.10+ CI Twitter


What is this?

Web3 Agent Kit is a Python framework for building AI agents that can autonomously interact with DeFi protocols, manage wallets, execute trades, and perform complex on-chain operations across multiple blockchains.

from web3_agent_kit import Agent, Wallet, Chain
from web3_agent_kit.defi import Uniswap

agent = Agent(
    wallet=Wallet.from_env("PRIVATE_KEY"),
    chains=[Chain.BASE],
    tools=[Uniswap()],
)

# Agent uses LLM reasoning to execute natural language goals
result = agent.run("Swap 0.1 ETH to USDC on Base")

โœจ Features

๐Ÿค– Core

  • ๐Ÿ”— Multi-chain support โ€” Ethereum, Base, Arbitrum, Optimism, Polygon, Avalanche, BSC
  • ๐Ÿง  LLM-powered reasoning โ€” Multi-provider cascade (OpenAI, Anthropic, Groq, DeepSeek, OpenRouter, Kimi)
  • ๐ŸŽฏ Natural language goals โ€” Tell the agent what to do in plain English
  • ๐Ÿ” Governed signing โ€” Safety caps, kill-switch, operator confirmation

๐Ÿ’ฐ DeFi

  • ๐Ÿ’ฑ Uniswap V2 swaps โ€” Actual token swaps with quotes, approvals, slippage protection
  • ๐ŸŒ‰ Cross-chain bridges โ€” Li.Fi + Socket aggregators for best routes
  • ๐Ÿ“Š Portfolio tracking โ€” Real-time balances, P&L across all chains

๐Ÿ”ซ Sniper

  • ๐ŸŽฏ Token sniper โ€” Monitor new liquidity pools, auto-buy safe tokens
  • ๐Ÿ›ก๏ธ Risk assessment โ€” Honeypot detection, liquidity checks, contract analysis
  • โšก Live monitoring โ€” Background thread with callback alerts

๐Ÿš€ Quick Start

Install

pip install web3-agent-kit

Environment Variables

# Required: Wallet
export PRIVATE_KEY="0x..."

# Required: At least one LLM provider
export OPENAI_API_KEY="sk-..."        # OpenAI
export ANTHROPIC_API_KEY="sk-ant-..."  # Anthropic (best reasoning)
export GROQ_API_KEY="gsk_..."          # Groq (fastest)
export DEEPSEEK_API_KEY="sk-..."       # DeepSeek (cheapest)

# Optional: Custom RPC endpoints
export ETH_RPC="https://..."
export BASE_RPC="https://..."

Basic Usage

from web3_agent_kit import Agent, Wallet, Chain, ChainManager
from web3_agent_kit.defi import Uniswap

# Setup
chain_manager = ChainManager(chains=[Chain.BASE])
wallet = Wallet.from_env("PRIVATE_KEY", chain_manager=chain_manager)
uniswap = Uniswap(chain_manager=chain_manager)

# Create agent with LLM reasoning
agent = Agent(
    wallet=wallet,
    chains=[Chain.BASE],
    tools=[uniswap],
)

# Natural language swap
result = agent.run("Swap 0.1 ETH to USDC on Base")
print(result)

๐Ÿ“ฆ Examples

Example Description
examples/llm_swap_agent.py LLM-powered natural language swapping
examples/direct_swap.py Programmatic Uniswap swap without LLM
examples/token_sniper.py Monitor new pairs, auto-buy safe tokens
examples/portfolio_dashboard.py Real-time portfolio across chains
examples/bridge_agent.py Cross-chain transfers via Li.Fi/Socket
examples/swap_agent.py Autonomous token swapping
examples/yield_optimizer.py Cross-chain yield farming
examples/airdrop_farmer.py Multi-chain airdrop farming
examples/sniper_bot.py Token launch sniper
examples/portfolio_tracker.py Portfolio tracking & reporting

๐Ÿง  LLM Integration

Multi-provider cascade with automatic fallback:

from web3_agent_kit.llm import LLM

# Auto-detect from environment variables
llm = LLM()

# Cascade order: Anthropic โ†’ Kimi โ†’ OpenRouter โ†’ DeepSeek โ†’ Groq โ†’ OpenAI

# Simple chat
response = llm.chat("What is the best yield on Base?")

# JSON response
data = llm.chat_json("Analyze this swap: 0.1 ETH to USDC")

Supported providers:

  • Anthropic (Claude) โ€” Best reasoning
  • OpenAI (GPT-4) โ€” General purpose
  • Groq (Llama) โ€” Fastest inference
  • DeepSeek โ€” Cheapest
  • OpenRouter โ€” Multi-model fallback
  • Kimi โ€” Long context

๐Ÿ”ซ Token Sniper

Monitor new liquidity pools and auto-buy safe tokens:

from web3_agent_kit import TokenSniper, SniperConfig, RiskLevel

config = SniperConfig(
    max_buy=0.005,          # max 0.005 ETH per snipe
    auto_buy=True,          # auto-buy safe tokens
    honeypot_check=True,    # check if token is honeypot
    min_liquidity=0.5,      # min 0.5 ETH liquidity
)

sniper = TokenSniper(chain_manager, wallet, config, uniswap=uniswap)

# Scan recent blocks
pairs = sniper.scan_recent_blocks(num_blocks=100, chain=Chain.BASE)

# Or start live monitoring
sniper.start(chain=Chain.BASE, poll_interval=12)

๐Ÿ“Š Portfolio Dashboard

Track balances and P&L across chains:

from web3_agent_kit import PortfolioTracker

tracker = PortfolioTracker(chain_manager, wallet)
summary = tracker.get_summary()

print(summary)
# ๐Ÿ“Š Portfolio: 0x1234...
# ๐Ÿ’ฐ Total Value: $12,345.67
#
#   ๐Ÿ”— ETHEREUM: $8,000.00
#      Native: 1.5000 ETH ($5,250.00)
#      USDC: 2750.0000 ($2,750.00)
#
#   ๐Ÿ”— BASE: $4,345.67
#      Native: 1.2000 ETH ($4,200.00)
#      USDC: 145.6700 ($145.67)

๐ŸŒ‰ Bridge Agent

Cross-chain transfers via Li.Fi and Socket:

from web3_agent_kit import BridgeAgent

bridge = BridgeAgent(chain_manager, wallet)

# Get best routes
routes = bridge.get_routes("ETH", 0.1, Chain.ETHEREUM, Chain.BASE)

for route in routes:
    print(f"{route.bridge_name}: {route.amount_out:.6f} ETH (fee: ${route.fee_usd:.2f})")

# Execute transfer
result = bridge.transfer("ETH", 0.1, Chain.ETHEREUM, Chain.BASE)
print(f"TX: {result.tx_hash}")

๐Ÿ—๏ธ Architecture

web3-agent-kit/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py    # Package exports
โ”‚   โ”œโ”€โ”€ agent.py       # Agent framework + LLM reasoning
โ”‚   โ”œโ”€โ”€ llm.py         # Multi-provider LLM client
โ”‚   โ”œโ”€โ”€ wallet.py      # Wallet management + signing
โ”‚   โ”œโ”€โ”€ chain.py       # Multi-chain RPC + config
โ”‚   โ”œโ”€โ”€ sniper.py      # Token sniper + monitoring
โ”‚   โ”œโ”€โ”€ portfolio.py   # Portfolio tracking + P&L
โ”‚   โ”œโ”€โ”€ bridge.py      # Cross-chain bridge agent
โ”‚   โ””โ”€โ”€ defi/
โ”‚       โ”œโ”€โ”€ __init__.py  # Uniswap, Aerodrome, Aave, Curve
โ”œโ”€โ”€ examples/           # Ready-to-use examples
โ”œโ”€โ”€ tests/              # Test suite
โ””โ”€โ”€ docs/               # Documentation

๐Ÿ” Safety

Web3 Agent Kit includes built-in safety features:

from web3_agent_kit.safety import SpendGovernor, SpendLimits

governor = SpendGovernor(
    limits=SpendLimits(
        max_per_tx=0.1,      # max 0.1 ETH per transaction
        daily_limit=1.0,     # max 1 ETH per day
    ),
    require_confirm=True,    # operator must confirm
)

# Kill switch for emergencies
governor.kill()   # blocks all transactions
governor.unkill() # resume

๐Ÿ› ๏ธ Supported Chains

Chain Status Uniswap Bridge
Ethereum โœ… โœ… โœ…
Base โœ… โœ… โœ…
Arbitrum โœ… โœ… โœ…
Optimism โœ… โœ… โœ…
Polygon โœ… โœ… โœ…
Avalanche โœ… โ€” โœ…
BSC โœ… โ€” โœ…
Solana ๐Ÿ”œ โ€” โ€”

๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.


๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


๐Ÿ™ Acknowledgments

Built with:


Built by Maulana ยท Twitter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

web3_agent_kit-0.3.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

web3_agent_kit-0.3.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file web3_agent_kit-0.3.0.tar.gz.

File metadata

  • Download URL: web3_agent_kit-0.3.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for web3_agent_kit-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6be1362ae21e60c069bbbb71b340626731758154f08484bab760b394daa76c99
MD5 5e041aa8ee41719129de0eb9d28c58f6
BLAKE2b-256 bd6299e9fb30de0831de7328cbc81f080dddf63fc0a34215dc459f83465701d6

See more details on using hashes here.

File details

Details for the file web3_agent_kit-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: web3_agent_kit-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for web3_agent_kit-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d166b5ace7205dc137869779c0b77b593d244feadefce4a0b4d9b447fb402b24
MD5 d7f46cb1320fd067b8a851c302ecd81e
BLAKE2b-256 2da8e1a46f1d6e7b330647e5fc1cfbe9a389ab59a0a53367289fc1ec78b2624a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page