Skip to content

Commit 306f16c

Browse files
leejw51cryptowtfsayocoderabbitai[bot]
authored
feat: Add Cronos Evm (#2585)
* feat: Add Cronos Evm - Created `@elizaos/plugin-cronos` with: - Support for Cronos Mainnet and Testnet - Token transfer functionality - Balance checking capability - Wallet provider implementation - `README.md`: Documentation and setup guide - Action handlers for transfers and balance checks - Chain configurations and wallet provider - TypeScript configurations and types - CRO/TCRO token support - Environment variable setup for private keys - Security guidelines for key management - Comprehensive API documentation feat: Enhance balance and transfer actions with validation and schema - Updated `BalanceAction` and `TransferAction` to include Zod validation schemas for parameters. - Replaced deprecated `generateObjectDeprecated` with `generateObject` for better type safety. - Improved error handling and logging for balance and transfer operations. - Added address validation to ensure proper Ethereum address format. - Updated templates to reflect new parameter requirements for balance checks. - Refactored wallet provider methods to support fetching balance by address. * Update packages/plugin-cronos/README.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Sayo <hi@sayo.wtf> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 91c9088 commit 306f16c

File tree

11 files changed

+1005
-0
lines changed

11 files changed

+1005
-0
lines changed

packages/plugin-cronos/README.md

+257
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# @elizaos/plugin-cronos
2+
3+
Cronos plugin for Eliza, extending the EVM plugin functionality.
4+
5+
## Supported Networks
6+
7+
### Mainnet
8+
- Cronos Mainnet (Chain ID: 25)
9+
- RPC Endpoint: https://evm.cronos.org/
10+
- Explorer: https://explorer.cronos.org/
11+
- Native Token: CRO
12+
13+
### Testnet
14+
- Cronos Testnet 3 (Chain ID: 338)
15+
- RPC Endpoint: https://evm-t3.cronos.org/
16+
- Explorer: https://cronos.org/explorer/testnet3
17+
- Native Token: TCRO
18+
19+
## Installation
20+
21+
```bash
22+
pnpm add @elizaos/plugin-cronos
23+
```
24+
25+
## Usage
26+
27+
### Basic Setup
28+
```typescript
29+
import { cronosPlugin } from "@elizaos/plugin-cronos";
30+
31+
// Use the plugin in your Eliza configuration
32+
const config = {
33+
plugins: [cronosPlugin],
34+
// ... rest of your config
35+
};
36+
```
37+
38+
### Character Configuration Guide
39+
40+
Create a `your-character.character.json` file with the following structure:
41+
42+
```json
43+
{
44+
"name": "YourCharacterName",
45+
"plugins": ["@elizaos/plugin-cronos"],
46+
"clients": ["telegram"],
47+
"modelProvider": "openai",
48+
"settings": {
49+
"secrets": {},
50+
"chains": {
51+
"evm": ["cronos", "cronosTestnet"]
52+
}
53+
},
54+
"system": "Primary function is to execute token transfers and check balances on Cronos chain.",
55+
"actions": {
56+
"SEND_TOKEN": {
57+
"enabled": true,
58+
"priority": 1,
59+
"force": true,
60+
"schema": {
61+
"type": "object",
62+
"properties": {
63+
"fromChain": {
64+
"type": "string",
65+
"description": "The chain to execute the transfer on",
66+
"enum": ["cronos", "cronosTestnet"]
67+
},
68+
"toAddress": {
69+
"type": "string",
70+
"description": "The recipient's wallet address",
71+
"pattern": "^0x[a-fA-F0-9]{40}$"
72+
},
73+
"amount": {
74+
"type": "string",
75+
"description": "The amount of tokens to transfer",
76+
"pattern": "^[0-9]*(\\.[0-9]+)?$"
77+
}
78+
},
79+
"required": ["fromChain", "toAddress", "amount"]
80+
},
81+
"triggers": [
82+
"send * CRO to *",
83+
"transfer * CRO to *"
84+
],
85+
"examples": [
86+
{
87+
"input": "Send 0.1 CRO to 0x...",
88+
"output": {
89+
"fromChain": "cronos",
90+
"toAddress": "0x...",
91+
"amount": "0.1"
92+
}
93+
}
94+
]
95+
},
96+
"CHECK_BALANCE": {
97+
"enabled": true,
98+
"priority": 1,
99+
"force": true,
100+
"schema": {
101+
"type": "object",
102+
"properties": {
103+
"chain": {
104+
"type": "string",
105+
"description": "The chain to check balance on",
106+
"enum": ["cronos", "cronosTestnet"]
107+
}
108+
},
109+
"required": ["chain"]
110+
},
111+
"triggers": [
112+
"check balance",
113+
"show balance",
114+
"what's my balance",
115+
"how much CRO do I have",
116+
"check balance on *",
117+
"show balance on *"
118+
],
119+
"examples": [
120+
{
121+
"input": "check balance",
122+
"output": {
123+
"chain": "cronos"
124+
}
125+
},
126+
{
127+
"input": "what's my balance on testnet",
128+
"output": {
129+
"chain": "cronosTestnet"
130+
}
131+
}
132+
]
133+
}
134+
},
135+
"messageExamples": [
136+
[
137+
{
138+
"user": "{{user1}}",
139+
"content": {
140+
"text": "Send 100 CRO to 0x..."
141+
}
142+
},
143+
{
144+
"user": "YourCharacterName",
145+
"content": {
146+
"text": "Processing token transfer...",
147+
"action": "SEND_TOKEN"
148+
}
149+
}
150+
],
151+
[
152+
{
153+
"user": "{{user1}}",
154+
"content": {
155+
"text": "What's my balance?"
156+
}
157+
},
158+
{
159+
"user": "YourCharacterName",
160+
"content": {
161+
"text": "Checking your balance...",
162+
"action": "CHECK_BALANCE"
163+
}
164+
}
165+
]
166+
]
167+
}
168+
```
169+
170+
#### Key Configuration Fields:
171+
172+
1. **Basic Setup**
173+
- `name`: Your character's name
174+
- `plugins`: Include `@elizaos/plugin-cronos`
175+
- `clients`: Supported client platforms
176+
177+
2. **Chain Settings**
178+
- Configure both mainnet and testnet in `settings.chains.evm`
179+
- Available options: `"cronos"` (mainnet) and `"cronosTestnet"`
180+
181+
3. **Action Configuration**
182+
- `SEND_TOKEN`: Action for token transfers
183+
- `CHECK_BALANCE`: Action for checking wallet balance
184+
- `schema`: Defines the required parameters for each action
185+
- `triggers`: Phrases that activate the actions
186+
- `examples`: Sample inputs and outputs
187+
188+
4. **Message Examples**
189+
- Provide example interactions
190+
- Show how actions are triggered
191+
- Demonstrate expected responses
192+
193+
### Action Examples
194+
```
195+
// Send tokens on mainnet
196+
"Send 0.1 CRO to 0x..." use mainnet
197+
198+
// Send tokens on testnet
199+
"Send 0.1 TCRO to 0x..." use testnet
200+
201+
// Check balance on mainnet
202+
"check balance"
203+
"what's my balance"
204+
"how much CRO do I have"
205+
206+
// Check balance on testnet
207+
"check balance on testnet"
208+
"what's my balance on testnet"
209+
```
210+
211+
## Features
212+
213+
- All standard EVM functionality inherited from @elizaos/plugin-evm
214+
- Preconfigured for both Cronos Mainnet and Testnet
215+
- Native CRO/TCRO token support
216+
- Automated token transfer actions
217+
- Balance checking functionality
218+
- Built-in chain configuration
219+
220+
## Environment Variables
221+
222+
Required environment variable for transactions:
223+
224+
```env
225+
# Wallet private key (Required, must start with 0x)
226+
CRONOS_PRIVATE_KEY=0x...
227+
```
228+
229+
### Security Warnings ⚠️
230+
231+
- **NEVER** commit private keys to version control
232+
- **NEVER** share private keys with anyone
233+
- **ALWAYS** use environment variables or secure key management
234+
- Use separate keys for mainnet and testnet
235+
- Monitor your wallet for unauthorized transactions
236+
237+
### Setup
238+
239+
1. Create `.env` file:
240+
```env
241+
CRONOS_PRIVATE_KEY=0x... # Mainnet
242+
```
243+
244+
2. For testnet development, use `.env.local`:
245+
```env
246+
CRONOS_PRIVATE_KEY=0x... # Testnet only
247+
```
248+
249+
3. Add to `.gitignore`:
250+
```
251+
.env
252+
.env.*
253+
```
254+
255+
## License
256+
257+
MIT

packages/plugin-cronos/package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@elizaos/plugin-cronos",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"main": "dist/index.js",
6+
"module": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"exports": {
9+
"./package.json": "./package.json",
10+
".": {
11+
"import": {
12+
"@elizaos/source": "./src/index.ts",
13+
"types": "./dist/index.d.ts",
14+
"default": "./dist/index.js"
15+
}
16+
}
17+
},
18+
"files": [
19+
"dist"
20+
],
21+
"scripts": {
22+
"build": "tsup --format esm --dts"
23+
},
24+
"dependencies": {
25+
"@elizaos/core": "workspace:*",
26+
"node-cache": "^5.1.2",
27+
"viem": "^2.0.0"
28+
},
29+
"devDependencies": {
30+
"tsup": "^8.0.1",
31+
"typescript": "^5.3.3"
32+
}
33+
}

0 commit comments

Comments
 (0)