@@ -5,8 +5,8 @@ A decentralized toss agent built using CDP AgentKit that operates over the XMTP
5
5
## Features
6
6
7
7
- XMTP group chat support (responds to @toss mentions)
8
- - Natural language bet creation (e.g., "Will it rain tomorrow for 10 USDC")
9
- - Support for custom betting topics and options
8
+ - Natural language toss creation (e.g., "Will it rain tomorrow for 10 USDC")
9
+ - Support for custom toss topics and options
10
10
- Multiple player support with option-based prize distribution
11
11
- Wallet address display for transparency and accountability
12
12
- Transaction hash links for payment verification
@@ -19,94 +19,31 @@ A decentralized toss agent built using CDP AgentKit that operates over the XMTP
19
19
- [ OpenAI] ( https://platform.openai.com/ ) API key
20
20
- [ Coinbase Developer Platform] ( https://portal.cdp.coinbase.com ) (CDP) API credentials
21
21
22
- ## Quick Start Guide
23
-
24
- Follow these steps to get your CoinToss agent up and running quickly:
25
-
26
- 1 . ** Clone the repository** :
27
-
28
- ``` bash
29
- git clone https://github.com/ephemeraHQ/xmtp-agent-examples.git
30
- cd integrations/cointoss
31
- ```
32
-
33
- 2 . ** Install dependencies** :
34
-
35
- ``` bash
36
- yarn install
37
- ```
38
-
39
- 3 . ** Generate XMTP keys** :
40
-
41
- ``` bash
42
- yarn build
43
- yarn gen:keys
44
- ```
45
-
46
- This will generate random wallet and encryption keys for your agent and output them to the console. Copy these values to your ` .env ` file.
47
-
48
-
49
- 4 . ** Set up your environment variables** :
50
- Create a ` .env ` file with the following variables:
51
-
52
- ```
53
- # Required: OpenAI API Key
54
- OPENAI_API_KEY=your_openai_api_key_here
55
-
56
- # Required: Coinbase Developer Platform credentials
57
- CDP_KEY_NAME=your_api_key_name_here
58
- CDP_API_KEY_PRIVATE_KEY=your_api_key_private_key_here
59
-
60
- # Required: XMTP wallet and encryption keys (from step 3)
61
- WALLET_KEY=your_wallet_private_key_here
62
- ENCRYPTION_KEY=your_encryption_key_here
63
-
64
- # Optional: Network ID (defaults to base-sepolia if not specified)
65
- NETWORK_ID=base-sepolia
66
-
67
- # Optional: Redis for persistent storage (if not provided, local file storage will be used)
68
- REDIS_URL=redis://localhost:6379
69
- ```
70
-
71
- 5 . ** Build and start the agent** :
72
-
73
- ``` bash
74
- yarn build
75
- yarn start
76
- ```
77
-
78
- For development with more detailed logs:
79
- ``` bash
80
- yarn dev
81
- ```
82
-
83
- 6 . ** Invite the agent to your XMTP group chat** :
84
- The agent responds when tagged with ` @toss ` in a group chat.
85
-
86
22
## Usage Examples
87
23
88
24
The agent responds to commands in group chats when tagged with ` @toss ` :
89
25
90
26
### Available Commands
91
27
92
- - ` @toss create <amount> ` - Create a new betting game with specified USDC amount
93
- - ` @toss join <gameId > <option> ` - Join a game and select your option
94
- - ` @toss execute <gameId > ` - Execute the bet resolution (creator only)
95
- - ` @toss status <gameId > ` - Check game status and participants
96
- - ` @toss list ` - List all active games
28
+ - ` @toss create <amount> ` - Create a new toss with specified USDC amount
29
+ - ` @toss join <tossId > <option> ` - Join a toss and select your option
30
+ - ` @toss execute <tossId > ` - Execute the toss resolution (creator only)
31
+ - ` @toss status <tossId > ` - Check toss status and participants
32
+ - ` @toss list ` - List all active tosses
97
33
- ` @toss balance ` - Check your wallet balance
98
- - ` @toss <natural language bet > ` - Create a bet using natural language
34
+ - ` @toss <natural language toss > ` - Create a toss using natural language
99
35
100
36
### Natural Language Examples
101
- - ` @toss Will it rain tomorrow for 5 ` - Creates a yes/no bet with 5 USDC
102
- - ` @toss Lakers vs Celtics game for 10 ` - Creates a bet with Lakers and Celtics as options
37
+
38
+ - ` @toss Will it rain tomorrow for 5 ` - Creates a yes/no toss with 5 USDC
39
+ - ` @toss Lakers vs Celtics game for 10 ` - Creates a toss with Lakers and Celtics as options
103
40
104
41
### Example Flow
105
42
106
- 1 . ** Create a game ** : ` @toss Will Bitcoin hit $100k this year for 5 `
107
- 2 . ** Join the game ** : ` @toss join 1 yes ` (each player must choose an option)
43
+ 1 . ** Create a toss ** : ` @toss Will Bitcoin hit $100k this year for 5 `
44
+ 2 . ** Join the toss ** : ` @toss join 1 yes ` (each player must choose an option)
108
45
3 . ** Check status** : ` @toss status 1 `
109
- 4 . ** Execute the bet ** : ` @toss execute 1 ` (creator only)
46
+ 4 . ** Execute the toss ** : ` @toss execute 1 ` (creator only)
110
47
5 . ** View results** : All players who chose the winning option share the prize pool
111
48
112
49
## How It Works
@@ -115,20 +52,21 @@ This CoinToss agent combines several technologies:
115
52
116
53
1 . ** XMTP Protocol** : For group chat messaging interface
117
54
2 . ** Coinbase AgentKit** : For wallet management and payments
118
- 3 . ** Storage Options** : Redis or local file storage for game and wallet data
119
- 4 . ** LLM Integration** : For natural language bet parsing
55
+ 3 . ** Storage Options** : Redis or local file storage for toss and wallet data
56
+ 4 . ** LLM Integration** : For natural language toss parsing
120
57
121
58
The agent workflow:
122
- 1 . Users create or join betting games in group chats
123
- 2 . Each player is assigned a unique wallet
124
- 3 . The game creator determines when to execute the bet
59
+
60
+ 1 . Users create or join tosses in group chats
61
+ 2 . Each player is assigned a unique wallet
62
+ 3 . The toss creator determines when to execute the toss
125
63
4 . A random option is selected as the winner
126
64
5 . Prize money is split among all players who chose the winning option
127
65
128
66
## Prize Distribution
129
67
130
- - All bets are collected in a dedicated game wallet
131
- - When the game is executed, a winning option is randomly selected
68
+ - All tosses are collected in a dedicated toss wallet
69
+ - When the toss is executed, a winning option is randomly selected
132
70
- All players who chose the winning option share the prize pool equally
133
71
- Automatic transfers are sent to each winner's wallet
134
72
- Transaction confirmations are provided in the chat
@@ -139,7 +77,8 @@ The agent workflow:
139
77
140
78
If you see errors like ` Failed to create wallet: APIError ` :
141
79
142
- 1 . ** Coinbase API Keys** :
80
+ 1 . ** Coinbase API Keys** :
81
+
143
82
- Verify your API key name matches exactly as shown in the Coinbase Developer Dashboard
144
83
- Ensure your private key includes the complete PEM format with BEGIN/END lines
145
84
- Format multiline keys properly for your .env file
@@ -149,6 +88,7 @@ If you see errors like `Failed to create wallet: APIError`:
149
88
- Verify there are no Coinbase service outages
150
89
151
90
If you're still encountering issues, try clearing your local wallet data:
91
+
152
92
``` bash
153
93
rm -rf .data/wallets
154
94
```
@@ -157,34 +97,33 @@ rm -rf .data/wallets
157
97
158
98
- ** Wallet Management** : Coinbase SDK for wallet creation and transfers
159
99
- ** XMTP Integration** : Group chat support with @toss tag handling
160
- - ** Unified Agent System** :
100
+ - ** Unified Agent System** :
161
101
- Single AI agent for both natural language parsing and wallet operations
162
- - ** Game Logic** :
102
+ - ** Toss Logic** :
163
103
- Random selection of winning option
164
104
- Fair prize distribution among winners
165
105
- ** Storage Options** : Local file storage or Redis
166
106
167
107
## Security
168
108
169
- - Each user and game gets a dedicated Coinbase wallet
109
+ - Each user and toss gets a dedicated Coinbase wallet
170
110
- Encrypted wallet storage
171
111
- Transparent wallet address display
172
112
- Transaction verification through block explorer links
173
113
- Advanced randomness for fair winner selection
174
114
175
- ## License
176
-
177
- MIT
178
-
179
- ## Code Structure
115
+ ## Run the agent
180
116
181
- The CoinToss agent codebase is organized with a modular design:
182
-
183
- - ** src/index.ts** : Main entry point that initializes the system and handles XMTP message routing
184
- - ** src/commands.ts** : Command processor that handles all explicit commands and natural language bets
185
- - ** src/cdp.ts** : Agent for natural language processing and wallet operations
186
- - ** src/game.ts** : Game logic implementation
187
- - ** src/storage.ts** : Storage layer for persisting games and wallet data
188
- - ** src/walletService.ts** : Wallet functions for creating and managing game wallets
189
- - ** src/xmtp.ts** : XMTP integration for messaging
190
- - ** src/types.ts** : Type definitions
117
+ ``` bash
118
+ # git clone repo
119
+ git clone https://github.com/ephemeraHQ/xmtp-agent-examples.git
120
+ # go to the folder
121
+ cd xmtp-agent-examples
122
+ cd examples/cointoss
123
+ # install packages
124
+ yarn
125
+ # generate random xmtp keys (optional)
126
+ yarn gen:keys
127
+ # run the example
128
+ yarn dev
129
+ ```
0 commit comments