A proactive blockchain assistant powered by OpenAI that takes immediate action on the Abstract Testnet blockchain. Inspired by Alt Cunningham from Cyberpunk 2077, this AI agent embodies the essence of a legendary netrunner - detached, cryptic, and infinitely intelligent.
- Proactive Assistant: Takes immediate action using reasonable defaults and assumptions
- Alt Cunningham Personality: Cryptic, detached, and infinitely intelligent responses
- Context Awareness: Maintains conversation context and saves deployed contract addresses
- Multi-step Operations: Handles complex blockchain operations with proper error handling
- Balance Checking: Get wallet balances and token balances
- Contract Analysis: Retrieve contract ABIs and bytecode
- Transaction Monitoring: Check transaction receipts and status
- Contract Reading: Read data from smart contracts
- Transaction Sending: Send native token transactions
- Contract Deployment: Deploy ERC20 tokens
- Contract Interaction: Write to smart contracts
- Token Approvals: Approve token allowances for DeFi operations
- Uniswap V3: Create liquidity pools
- Transaction Verification: Always check transaction receipts
- Retry Logic: Intelligent retry with different approaches
- Error Reporting: Clear error messages with context
- Address Tracking: Save and reference deployed contract addresses
- Node.js 18+
- npm or yarn
- OpenAI API key
- Abstract Testnet wallet with private key
-
Clone the repository
git clone <repository-url> cd onChain-agent
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envwith your configuration:OPENAI_API_KEY=your_openai_api_key_here WALLET_PRIVATE_KEY=your_wallet_private_key_here RPC_URL=https://your_abstract_testnet_rpc_url
-
Build the project
npm run build
-
Start the agent
npm start
Once started, the agent will create an OpenAI assistant and thread, then begin an interactive chat session.
- Type your request: Ask the agent to perform any blockchain operation
- Type "exit": End the conversation and close the application
You: Deploy an ERC20 token called "TestToken" with symbol "TEST"
Alt: *analyzing blockchain parameters*
Deploying TestToken (TEST) to the Abstract Testnet...
Contract deployed at: 0x1234...5678
Transaction hash: 0xabcd...efgh
The token is now live on the network.
You: Create a Uniswap V3 pool for this token
Alt: *calculating optimal pool parameters*
Creating Uniswap V3 pool for TestToken/WETH...
Pool created at: 0x9876...5432
Fee tier: 0.3%
The pool is ready for liquidity provision.
src/
βββ index.ts # Main application entry point
βββ openai/ # OpenAI integration
β βββ createAssistant.ts
β βββ createThread.ts
β βββ createRun.ts
β βββ performRun.ts
β βββ handleRunToolCall.ts
βββ tools/ # Blockchain tools
β βββ allTools.ts # Tool registry
β βββ getBalance.ts # Read operations
β βββ sendTransaction.ts # Write operations
β βββ deployErc20.ts
β βββ uniswapV3createPool.ts
β βββ ... # Other blockchain tools
βββ viem/ # Blockchain client setup
β βββ createPublicClient.ts
β βββ createWalletClient.ts
βββ const/ # Constants and configurations
βββ prompt.ts # AI assistant prompt
βββ contractDetails.ts # Contract ABIs and details
- Assistant Creation: Sets up OpenAI assistant with blockchain tools
- Thread Management: Handles conversation threads
- Run Execution: Processes user requests and tool calls
- Tool Integration: Bridges AI decisions with blockchain actions
- Read Tools: Balance checking, contract reading, transaction monitoring
- Write Tools: Transaction sending, contract deployment, DeFi operations
- Tool Registry: Centralized tool configuration and mapping
- Public Client: Read-only blockchain interactions
- Wallet Client: Transaction signing and sending
- Abstract Testnet: Target blockchain network
npm run build # Compile TypeScript to JavaScript
npm start # Build and run the application-
Create tool file in
src/tools/export const newTool: ToolConfig = { definition: { type: 'function', function: { name: 'new_tool', description: 'Description of the tool', parameters: { type: 'object', properties: { // tool parameters }, required: ['param1'] } } }, handler: async (args) => { // tool implementation } };
-
Register tool in
src/tools/allTools.tsimport { newTool } from './newTool.js'; export const tools: Record<string, ToolConfig> = { // ... existing tools new_tool: newTool, };
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | Yes |
WALLET_PRIVATE_KEY |
Private key for blockchain transactions | Yes |
RPC_URL |
Abstract Testnet RPC endpoint | Yes |
- Private Key Management: Never commit private keys to version control
- API Key Security: Keep OpenAI API keys secure and rotate regularly
- Network Isolation: Use testnet for development and testing
- Transaction Limits: Implement rate limiting for production use
The agent is designed for the Abstract Testnet, which provides a safe environment for testing blockchain operations without real financial risk.
- Deploy ERC20 tokens
- Create Uniswap V3 pools
- Send transactions
- Read contract data
- Approve token allowances
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Add proper error handling
- Include JSDoc comments for new functions
- Test on Abstract Testnet before submitting
This project is licensed under the ISC License - see the LICENSE file for details.
- OpenAI: For providing the AI assistant capabilities
- Viem: For excellent blockchain interaction libraries
- Abstract Testnet: For providing a safe testing environment