A TypeScript project that implements an OpenAI Assistant with custom tool integration capabilities, specifically designed for handling onchain transactions and wallet interactions.
- Custom OpenAI Assistant creation and management
- Tool integration framework for blockchain interactions
- Wallet balance checking functionality
- Asynchronous run management with status polling
- Error handling for tool executions
-
Assistant Creation (
create-assistant.ts)- Creates a specialized onchain assistant
- Configures available tools and instructions
- Uses GPT-4 model for processing
-
Tool Handler (
handle-tools.ts)- Manages tool execution lifecycle
- Processes assistant's tool requests
- Handles tool output submission
- Includes comprehensive error handling
-
Run Management (
manage-run.ts)- Creates and monitors assistant runs
- Implements status polling mechanism
- Ensures proper run state management
- Node.js
- OpenAI API key
- Private Key of a wallet
- TypeScript
- Clone the repository
git clone https://github.com/jinali98/onchain-ai-agent-evm.git- Install dependencies
npm install- Set up your environment variables
OPENAI_API_KEY=your_api_key_here
PRIVATE_KEY=your_wallet_private_key
ASSISTANT_ID=optional_assistant_id- Create an assistant:
const assistant = await createAssistant(openai);- Create and manage a run:
const run = await createRun(openai, thread, assistant);- Handle tool executions:
await handleTools(openai, run, thread);getWalletBalance: Retrieves the balance of a specified wallet address