|
| 1 | +# Payment Agent |
| 2 | + |
| 3 | +A sophisticated DeFi payment agent built using Coinbase's AgentKit and LangChain, operating over the XMTP messaging protocol. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Process blockchain payments using natural language commands |
| 8 | +- Advanced language processing using LangChain and OpenAI |
| 9 | +- User-specific wallet management with flexible storage options (Redis or local file) |
| 10 | +- XMTP messaging integration for secure, decentralized chat interactions |
| 11 | +- Powered by CDP SDK for reliable blockchain operations and Langchain for AI Agent |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- Node.js (v20+) |
| 16 | +- [OpenAI](https://platform.openai.com/) API key |
| 17 | +- [Coinbase Developer Platform](https://portal.cdp.coinbase.com) (CDP) API credentials |
| 18 | +- Yarn package manager |
| 19 | + |
| 20 | +## Quick Start Guide |
| 21 | + |
| 22 | +Follow these steps to get your payment agent up and running: |
| 23 | + |
| 24 | +1. **Clone the repository**: |
| 25 | + |
| 26 | + ```bash |
| 27 | + git clone https://github.com/ephemeraHQ/xmtp-agent-examples.git |
| 28 | + cd integrations/paymentagent |
| 29 | + ``` |
| 30 | + |
| 31 | +2. **Install dependencies**: |
| 32 | + |
| 33 | + ```bash |
| 34 | + yarn install |
| 35 | + ``` |
| 36 | + |
| 37 | +3. **Generate XMTP keys**: |
| 38 | + |
| 39 | + ```bash |
| 40 | + yarn gen:keys |
| 41 | + ``` |
| 42 | + |
| 43 | + This will generate random wallet and encryption keys for your agent and output them to the console. Copy these values to your `.env` file. |
| 44 | + |
| 45 | +4. **Set up your environment variables**: |
| 46 | + Create a `.env` file with the following variables: |
| 47 | + |
| 48 | + ``` |
| 49 | + # Required: OpenAI API Key |
| 50 | + OPENAI_API_KEY=your_openai_api_key_here |
| 51 | +
|
| 52 | + # Required: Coinbase Developer Platform credentials |
| 53 | + CDP_API_KEY_NAME=your_cdp_api_key_name_here |
| 54 | + CDP_API_KEY_PRIVATE_KEY=your_cdp_api_key_private_key_here |
| 55 | +
|
| 56 | + # Required: XMTP wallet and encryption keys (from step 3) |
| 57 | + WALLET_KEY=your_wallet_private_key_here |
| 58 | + ENCRYPTION_KEY=your_encryption_key_here |
| 59 | + XMTP_ENV="local" # or "dev" or "production" |
| 60 | +
|
| 61 | + # Optional: Network ID (defaults to base-sepolia if not specified) |
| 62 | + NETWORK_ID=base-sepolia # or base-mainnet |
| 63 | +
|
| 64 | + # Optional: Redis for persistent storage (if not provided, local file storage will be used) |
| 65 | + REDIS_URL=your_redis_url_here |
| 66 | + ``` |
| 67 | + |
| 68 | +5. **Start the agent**: |
| 69 | + |
| 70 | + ```bash |
| 71 | + yarn dev |
| 72 | + ``` |
| 73 | + |
| 74 | +6. **Interact with your agent**: |
| 75 | + Once running, you'll see a URL in the console like: |
| 76 | + ``` |
| 77 | + Send a message on http://xmtp.chat/dm/YOUR_AGENT_ADDRESS?env=dev |
| 78 | + ``` |
| 79 | + Open this URL in your browser to start chatting with your payment agent! |
| 80 | + |
| 81 | +## Usage Examples |
| 82 | + |
| 83 | +Once the agent is running, you can interact with it using natural language commands: |
| 84 | + |
| 85 | +### Basic prompts |
| 86 | + |
| 87 | +- "Send 0.01 ETH to 0x1234..." |
| 88 | +- "Check my wallet balance" |
| 89 | +- "Transfer 10 USDC to vitalik.eth" |
| 90 | + |
| 91 | +## How It Works |
| 92 | + |
| 93 | +This payment agent combines several technologies: |
| 94 | + |
| 95 | +1. **XMTP Protocol**: For decentralized messaging and chat interface |
| 96 | +2. **Langchain**: AI agent framework |
| 97 | +3. **CDP SDK**: Blockchain Operations |
| 98 | +4. **Storage Options**: Redis or local file storage for wallet data |
| 99 | +5. **LLM Integration**: For natural language processing |
| 100 | + |
| 101 | +The payment agent integrates several key technologies: |
| 102 | + |
| 103 | +1. **XMTP Protocol**: Provides decentralized messaging infrastructure |
| 104 | +2. **LangChain**: Powers natural language processing and conversation flow |
| 105 | +3. **Coinbase AgentKit**: Handles blockchain interactions and wallet management |
| 106 | +4. **Storage Layer**: Flexible storage with Redis or local file system |
| 107 | +5. **OpenAI Integration**: Advanced language understanding and response generation |
| 108 | + |
| 109 | +### Key Components |
| 110 | + |
| 111 | +- `src/index.ts`: Main application entry point |
| 112 | +- `src/cdp.ts`: Coinbase Developer Platform integration |
| 113 | +- `src/xmtp.ts`: XMTP messaging protocol implementation |
| 114 | +- `src/langchain.ts`: LangChain agent and processing logic |
| 115 | +- `src/storage.ts`: Data persistence layer |
| 116 | + |
| 117 | +## Troubleshooting |
| 118 | + |
| 119 | +Common issues and solutions: |
| 120 | + |
| 121 | +### Connection Issues |
| 122 | + |
| 123 | +- Verify XMTP environment settings match your needs (`local`, `dev`, or `production`) |
| 124 | +- Check Redis connection string if using Redis storage |
| 125 | +- Ensure CDP API credentials are correctly formatted |
| 126 | +- Verify OpenAI API key has sufficient quota |
| 127 | + |
| 128 | +### Transaction Issues |
| 129 | + |
| 130 | +- Confirm wallet has sufficient balance for transactions |
| 131 | +- Check network settings match your intended network |
| 132 | +- Verify gas price settings for your chosen network |
| 133 | +- For testnets, ensure you've obtained test tokens from a faucet |
| 134 | + |
| 135 | +### Storage Issues |
| 136 | + |
| 137 | +- If Redis connection fails, the system will automatically fall back to local storage |
| 138 | +- Check file permissions if using local storage |
| 139 | +- Verify Redis URL format if using Redis |
| 140 | + |
| 141 | +### Transaction Failures |
| 142 | + |
| 143 | +- Check that you're on the correct network (default is base-sepolia) |
| 144 | +- Ensure the wallet has sufficient funds for the transaction |
| 145 | +- For testnet operations, request funds from a faucet |
0 commit comments