|
| 1 | +# @elizaos/plugin-evm |
| 2 | + |
| 3 | +This plugin provides actions and providers for interacting with EVM-compatible chains. |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +The EVM plugin provides comprehensive functionality for interacting with EVM-compatible chains, including token transfers, cross-chain bridging, and token swaps using LiFi integration. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- Multi-chain support with dynamic chain configuration |
| 12 | +- Native token transfers |
| 13 | +- Cross-chain token bridging via LiFi |
| 14 | +- Token swapping on supported DEXs |
| 15 | +- Wallet balance tracking |
| 16 | +- Custom RPC endpoint configuration |
| 17 | +- Automatic retry mechanisms |
| 18 | +- Comprehensive transaction management |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +```bash |
| 23 | +pnpm install @elizaos/plugin-evm |
| 24 | +``` |
| 25 | + |
| 26 | +## Configuration |
| 27 | + |
| 28 | +### Required Environment Variables |
| 29 | + |
| 30 | +```env |
| 31 | +# Required |
| 32 | +EVM_PRIVATE_KEY=your-private-key-here |
| 33 | +
|
| 34 | +# Optional - Custom RPC URLs |
| 35 | +EVM_PROVIDER_URL=https://your-custom-mainnet-rpc-url |
| 36 | +ETHEREUM_PROVIDER_<CHAIN_NAME>=https://your-custom-rpc-url |
| 37 | +``` |
| 38 | + |
| 39 | +### Chain Configuration |
| 40 | + |
| 41 | +By default, **Ethereum mainnet** is enabled. To enable additional chains, add them to your character config: |
| 42 | + |
| 43 | +```json |
| 44 | +"settings": { |
| 45 | + "chains": { |
| 46 | + "evm": [ |
| 47 | + "base", "arbitrum", "iotex" |
| 48 | + ] |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +Note: The chain names must match those in the viem/chains. |
| 54 | + |
| 55 | +### Custom RPC URLs |
| 56 | + |
| 57 | +By default, the RPC URL is inferred from the `viem/chains` config. To use a custom RPC URL for a specific chain, add the following to your `.env` file: |
| 58 | + |
| 59 | +```env |
| 60 | +ETHEREUM_PROVIDER_<CHAIN_NAME>=https://your-custom-rpc-url |
| 61 | +``` |
| 62 | + |
| 63 | +**Example usage:** |
| 64 | + |
| 65 | +```env |
| 66 | +ETHEREUM_PROVIDER_IOTEX=https://iotex-network.rpc.thirdweb.com |
| 67 | +``` |
| 68 | + |
| 69 | +#### Custom RPC for Ethereum Mainnet |
| 70 | + |
| 71 | +To set a custom RPC URL for Ethereum mainnet, use: |
| 72 | + |
| 73 | +```env |
| 74 | +EVM_PROVIDER_URL=https://your-custom-mainnet-rpc-url |
| 75 | +``` |
| 76 | + |
| 77 | +## Provider |
| 78 | + |
| 79 | +The **Wallet Provider** initializes with the **first chain in the list** as the default (or Ethereum mainnet if none are added). It: |
| 80 | + |
| 81 | +- Provides the **context** of the currently connected address and its balance. |
| 82 | +- Creates **Public** and **Wallet clients** to interact with the supported chains. |
| 83 | +- Allows adding chains dynamically at runtime. |
| 84 | + |
| 85 | +## Actions |
| 86 | + |
| 87 | +### 1. Transfer |
| 88 | + |
| 89 | +Transfer native tokens on the same chain: |
| 90 | + |
| 91 | +```typescript |
| 92 | +// Example: Transfer 1 ETH |
| 93 | +Transfer 1 ETH to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e |
| 94 | +``` |
| 95 | + |
| 96 | +### 2. Bridge |
| 97 | + |
| 98 | +Bridge tokens between different chains using LiFi: |
| 99 | + |
| 100 | +```typescript |
| 101 | +// Example: Bridge ETH from Ethereum to Base |
| 102 | +Bridge 1 ETH from Ethereum to Base |
| 103 | +``` |
| 104 | + |
| 105 | +### 3. Swap |
| 106 | + |
| 107 | +Swap tokens on the same chain using LiFi: |
| 108 | + |
| 109 | +```typescript |
| 110 | +// Example: Swap ETH for USDC |
| 111 | +Swap 1 ETH for USDC on Base |
| 112 | +``` |
| 113 | + |
| 114 | +## Development |
| 115 | + |
| 116 | +1. Clone the repository |
| 117 | +2. Install dependencies: |
| 118 | + |
| 119 | +```bash |
| 120 | +pnpm install |
| 121 | +``` |
| 122 | + |
| 123 | +3. Build the plugin: |
| 124 | + |
| 125 | +```bash |
| 126 | +pnpm run build |
| 127 | +``` |
| 128 | + |
| 129 | +4. Run tests: |
| 130 | + |
| 131 | +```bash |
| 132 | +pnpm test |
| 133 | +``` |
| 134 | + |
| 135 | +## API Reference |
| 136 | + |
| 137 | +### Core Components |
| 138 | + |
| 139 | +1. **WalletProvider** |
| 140 | + |
| 141 | + - Manages wallet connections |
| 142 | + - Handles chain switching |
| 143 | + - Manages RPC endpoints |
| 144 | + - Tracks balances |
| 145 | + |
| 146 | +2. **Actions** |
| 147 | + - TransferAction: Native token transfers |
| 148 | + - BridgeAction: Cross-chain transfers |
| 149 | + - SwapAction: Same-chain token swaps |
| 150 | + |
| 151 | +## Future Enhancements |
| 152 | + |
| 153 | +1. **Cross-Chain Operations** |
| 154 | + |
| 155 | + - Enhanced bridge aggregation |
| 156 | + - Multi-chain transaction batching |
| 157 | + - Cross-chain liquidity management |
| 158 | + - Bridge fee optimization |
| 159 | + - Chain-specific gas strategies |
| 160 | + - Cross-chain messaging |
| 161 | + |
| 162 | +2. **DeFi Integration** |
| 163 | + |
| 164 | + - Advanced swap routing |
| 165 | + - Yield farming automation |
| 166 | + - Liquidity pool management |
| 167 | + - Position management tools |
| 168 | + - MEV protection features |
| 169 | + - Flash loan integration |
| 170 | + |
| 171 | +3. **Smart Contract Management** |
| 172 | + |
| 173 | + - Contract deployment templates |
| 174 | + - Verification automation |
| 175 | + - Upgrade management |
| 176 | + - Security analysis tools |
| 177 | + - Gas optimization |
| 178 | + - ABI management system |
| 179 | + |
| 180 | +4. **Token Operations** |
| 181 | + |
| 182 | + - Batch transfer tools |
| 183 | + - Token approval management |
| 184 | + - Token metadata handling |
| 185 | + - Custom token standards |
| 186 | + - Token bridging optimization |
| 187 | + - NFT support enhancement |
| 188 | + |
| 189 | +5. **Wallet Features** |
| 190 | + |
| 191 | + - Multi-signature support |
| 192 | + - Account abstraction |
| 193 | + - Hardware wallet integration |
| 194 | + - Social recovery options |
| 195 | + - Transaction simulation |
| 196 | + - Batch transaction processing |
| 197 | + |
| 198 | +6. **Network Management** |
| 199 | + |
| 200 | + - Dynamic RPC management |
| 201 | + - Network health monitoring |
| 202 | + - Fallback provider system |
| 203 | + - Custom network addition |
| 204 | + - Gas price optimization |
| 205 | + - Network analytics |
| 206 | + |
| 207 | +7. **Security Enhancements** |
| 208 | + |
| 209 | + - Transaction validation |
| 210 | + - Risk assessment tools |
| 211 | + - Fraud detection |
| 212 | + - Rate limiting |
| 213 | + - Emergency shutdown |
| 214 | + - Audit integration |
| 215 | + |
| 216 | +8. **Developer Tools** |
| 217 | + - Enhanced debugging |
| 218 | + - Testing framework |
| 219 | + - Documentation generator |
| 220 | + - CLI improvements |
| 221 | + - Performance profiling |
| 222 | + - Integration templates |
| 223 | + |
| 224 | +We welcome community feedback and contributions to help prioritize these enhancements. |
| 225 | + |
| 226 | +## Contributing |
| 227 | + |
| 228 | +The plugin contains tests. Whether you're using **TDD** or not, please make sure to run the tests before submitting a PR: |
| 229 | + |
| 230 | +```bash |
| 231 | +pnpm test |
| 232 | +``` |
| 233 | + |
| 234 | +Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information. |
| 235 | + |
| 236 | +## Credits |
| 237 | + |
| 238 | +This plugin integrates with and builds upon several key technologies: |
| 239 | + |
| 240 | +- [Ethereum](https://ethereum.org/): Decentralized blockchain |
| 241 | +- [LiFi](https://lifi.io/): Cross-chain bridge and swap service |
| 242 | +- [viem](https://viem.sh/): Ethereum client library |
| 243 | +- [wagmi](https://wagmi.sh/): Ethereum client library |
| 244 | + |
| 245 | +Special thanks to: |
| 246 | + |
| 247 | +- [Ethereum Developer community](https://ethereum.org/developers/) |
| 248 | +- The Eliza community for their contributions and feedback |
| 249 | + |
| 250 | +For more information about EVM capabilities: |
| 251 | + |
| 252 | +- [Ethereum Documentation](https://ethereum.org/developers/) |
| 253 | +- [LiFi Documentation](https://lifi.io) |
| 254 | +- [viem Documentation](https://viem.sh) |
| 255 | +- [wagmi Documentation](https://wagmi.sh) |
| 256 | + |
| 257 | +## License |
| 258 | + |
| 259 | +This plugin is part of the Eliza project. See the main project repository for license information. |
0 commit comments