Skip to content

brewitmoney/bhindi-agent

Repository files navigation

Bhindi Brewit Agent

A TypeScript-based agent built using Bhindi.io specification.

What is Brewit?

Brewit provides crypto accounts for individuals and teams. Using the Brewit agent, users can interact and perform crypto transactions on their Brewit account

What is Bhindi?

Bhindi lets you talk to your apps like you talk to a friend. Bhindi supports 100+ integrations and is the easiest way to build AI agents.

Check a list of integrations available at Bhindi Agents Directory

๐Ÿ“š Documentation

For comprehensive documentation on building agents, visit the Bhindi Documentation.

Checkout Brewit Documentation to add features to agent.

โœจ Features

Token Operations

  • Token Swaps: Swap between different tokens on any supported chain
  • Multi-Transfer Support: Send single or multiple token transfers in a single transaction
  • Confirmation required: User confirmation for all token operations
  • Cross-chain Support: Works with multiple blockchain networks

๐Ÿš€ Available Tools

Token Operation Tools

Tool Description Special Features
swap Swap tokens from one token to another on any chain confirmationRequired: true
send Send single or multiple token transfers in a single transaction confirmationRequired: true

Tool Parameters

Swap Tool

  • toToken (string): The token address to swap to
  • fromToken (string): The token address to swap from
  • amount (string): The amount of tokens to swap

Send Tool

  • transfers (array): Array of token transfers to execute
    • toAddress (string): The recipient address to send tokens to
    • amount (string): The amount of token to send
    • token (string): The token address to send

๐Ÿ“‹ Quick Start

1. Install Dependencies

npm install

2. Build the Project

npm run build

3. Start the Server

npm start
# or for development with auto-reload:
npm run dev

4. Test the API

# Get available tools
curl -X GET "http://localhost:3000/tools"

# Test token swap
curl -X POST "http://localhost:3000/tools/swap" \
  -H "Content-Type: application/json" \
  -H "x-agent-delegation-key: your-delegation-key" \
  -d '{
    "toToken": "0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C",
    "fromToken": "0x0000000000000000000000000000000000000000",
    "amount": "1.0"
  }'

# Test multi-token send
curl -X POST "http://localhost:3000/tools/send" \
  -H "Content-Type: application/json" \
  -H "x-agent-delegation-key: your-delegation-key" \
  -d '{
    "transfers": [
      {
        "toAddress": "0x1234567890123456789012345678901234567890",
        "amount": "100",
        "token": "0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C"
      }
    ]
  }'

๐Ÿงฎ Usage Examples

Token Operations

# Token Swap
curl -X POST "http://localhost:3000/tools/swap" \
  -H "Content-Type: application/json" \
  -H "x-agent-delegation-key: your-delegation-key" \
  -d '{
    "toToken": "0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C",
    "fromToken": "0x0000000000000000000000000000000000000000",
    "amount": "1.0"
  }'

# Single Token Transfer
curl -X POST "http://localhost:3000/tools/send" \
  -H "Content-Type: application/json" \
  -H "x-agent-delegation-key: your-delegation-key" \
  -d '{
    "transfers": [
      {
        "toAddress": "0x1234567890123456789012345678901234567890",
        "amount": "100",
        "token": "0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C"
      }
    ]
  }'

# Multiple Token Transfers (Batch)
curl -X POST "http://localhost:3000/tools/send" \
  -H "Content-Type: application/json" \
  -H "x-agent-delegation-key: your-delegation-key" \
  -d '{
    "transfers": [
      {
        "toAddress": "0x1234567890123456789012345678901234567890",
        "amount": "100",
        "token": "0xA0b86a33E6441b8c4C8C0C4C0C4C0C4C0C4C0C4C"
      },
      {
        "toAddress": "0x0987654321098765432109876543210987654321",
        "amount": "50",
        "token": "0x0000000000000000000000000000000000000000"
      }
    ]
  }'

# Expected response:
{
  "success": true,
  "responseType": "mixed",
  "data": {
    "result": "Transaction hash or result data",
    "message": "Successfully executed swap operation",
    "tool_type": "brewit"
  }
}

๐Ÿ” Authentication

This agent requires authentication for all tool operations:

  • x-agent-delegation-key: Required header for all tool execution requests
  • The agent automatically verifies the delegation key and retrieves:
    • Validator Salt: For transaction validation
    • Account Address: For transaction execution
    • Chain IDs: Supported blockchain networks

๐Ÿ“š API Endpoints

  • GET / - Landing page (serves README.md content)
  • GET /tools - Get list of available tools
  • POST /tools/:toolName - Execute a specific tool (requires x-agent-delegation-key header)
  • GET /health - Health check endpoint
  • GET /docs - Swagger UI documentation (serves public/swagger.json)
  • GET /info - Get account information and validator configuration

๐Ÿ“– Documentation & Examples

  • Complete API Examples - Detailed usage examples for all tools with curl commands
  • Swagger Documentation - Available at /docs endpoint when server is running
  • Postman Collection - Import Bhind-Agent-Starter.postman_collection.json for easy testing

๐Ÿ—๏ธ Project Structure

src/
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ tools.json          # Tool definitions with JSON Schema
โ”œโ”€โ”€ controllers/
โ”‚   โ””โ”€โ”€ appController.ts    # Handles token operations
โ”œโ”€โ”€ services/
โ”‚   โ””โ”€โ”€ BrewitService.ts   # Brewit Money API integration
โ”œโ”€โ”€ routes/
โ”‚   โ”œโ”€โ”€ toolsRoutes.ts     # GET /tools endpoint
โ”‚   โ””โ”€โ”€ appRoutes.ts       # POST /tools/:toolName endpoint
โ”œโ”€โ”€ middlewares/
โ”‚   โ”œโ”€โ”€ auth.ts            # Authentication utilities
โ”‚   โ””โ”€โ”€ errorHandler.ts    # Error handling middleware
โ”œโ”€โ”€ types/
โ”‚   โ””โ”€โ”€ agent.ts           # Response type definitions
โ”œโ”€โ”€ __tests__/            # Test files
โ”œโ”€โ”€ app.ts                # Express app configuration
โ””โ”€โ”€ server.ts             # Server entry point

๐Ÿงช Development

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Lint code
npm run lint

# Format code
npm run format

# Development server with auto-reload
npm run dev

About

Bhindi Brewit Agent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors