Skip to content

zakkycrypt01/onchain-pa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

333 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Onchain Agent Powered by AgentKit

This is a Next.js project bootstrapped with create-onchain-agent.

It integrates AgentKit with Google Generative AI to provide intelligent AI-driven interactions with on-chain capabilities using the Gemini 2.5 Flash model.

Features

  • AI-Powered Agent: Uses Google's Gemini 2.5 Flash LLM for intelligent decision-making
  • On-Chain Capabilities: Interact with blockchain networks via AgentKit
  • Smart Wallet Management: Integrated CDP Smart Wallet support
  • Real-Time Chat Interface: Interactive web UI for agent communication
  • Function Response Serialization: Handles proper JSON serialization of tool responses for LLM compatibility

Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Google Generative AI API key (Get one here)
  • Coinbase Developer Platform (CDP) credentials

Installation

  1. Install dependencies:
npm install
  1. Configure your environment variables by copying the template:
cp .env.local .env.local
  1. Add your credentials to .env.local:
# Required: Google Generative AI
GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_here

# Required: Coinbase Developer Platform
CDP_API_KEY_ID=your_key_id
CDP_API_KEY_SECRET=your_key_secret
CDP_WALLET_SECRET=your_wallet_secret

# Optional: Network configuration
NETWORK_ID=base-sepolia
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser

Project Structure

app/
├── api/agent/
│   ├── route.ts              # Main API endpoint for agent interactions
│   ├── create-agent.ts       # Agent initialization and LLM configuration
│   └── prepare-agentkit.ts   # AgentKit and wallet provider setup
├── hooks/
│   └── useAgent.ts           # React hook for agent communication
├── types/
│   └── api.ts                # TypeScript type definitions
└── page.tsx                  # Main chat interface

Configuring Your Agent

You can customize your agent's behavior and capabilities:

1. Modify the LLM Model

Edit /api/agent/create-agent.ts to use a different Google Generative AI model or adjust model parameters like temperature and max tokens.

2. Configure the Wallet Provider

Edit /api/agent/prepare-agentkit.ts to change the blockchain network, wallet type, or network settings.

3. Add or Remove Action Providers

The agent comes with the following action providers enabled:

  • walletActionProvider() - Basic wallet operations
  • wethActionProvider() - WETH token interactions
  • erc20ActionProvider() - ERC-20 token operations
  • cdpApiActionProvider() - CDP API actions
  • cdpSmartWalletActionProvider() - Smart wallet operations
  • pythActionProvider() - Python oracle data
  • x402ActionProvider() - Payment operations

You can modify these in the AgentKit.from() configuration.

Technical Implementation

Tool Response Handling

This project includes a custom wrapper for agent tools that ensures all responses are properly serialized as JSON objects before being sent to the Google Generative AI API. This prevents validation errors when tools return formatted string responses.

The wrapper automatically:

  • Converts formatted string responses to structured JSON objects
  • Parses nested sections (like wallet network details) into proper object hierarchies
  • Provides fallback handling for unparseable responses

See /api/agent/route.ts for the implementation.

Troubleshooting

"Google Generative AI API key is missing"

Make sure GOOGLE_GENERATIVE_AI_API_KEY is set in your .env.local file and the development server has been restarted.

"CDP credentials are missing"

Ensure all three CDP credentials are configured:

  • CDP_API_KEY_ID
  • CDP_API_KEY_SECRET
  • CDP_WALLET_SECRET

"bigint: Failed to load bindings"

This is a warning about native module compilation. It's not critical - the application will fall back to pure JavaScript. You can try running npm run rebuild to compile native modules for your environment.

Production Deployment

Before deploying to production:

  1. Build the project:
npm run build
  1. Start the production server:
npm start
  1. Ensure all environment variables are properly set in your production environment
  2. Use environment-specific secrets management for sensitive credentials

Next Steps

Learn More

Contributing

Interested in contributing to AgentKit? Follow the contribution guide:

License

This project is part of the AgentKit ecosystem. See the AgentKit repository for license information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages