riglr-evm-tools
Production-grade EVM blockchain tools for riglr agents, providing comprehensive Ethereum and EVM-compatible chain interactions.
Features
- 🔐 Secure Transaction Management: Thread-safe SignerContext pattern for multi-tenant key management
- 💰 Balance Operations: Check ETH and ERC20 token balances with ApplicationContext
- 📤 Token Transfers: Send ETH and ERC20 tokens with SignerContext and automatic gas estimation
- 🔄 DeFi Integration: Uniswap V3 support for token swaps and liquidity operations
- 🌐 Multi-Chain Support: Works with Ethereum, Polygon, Arbitrum, Optimism, Base, and more
- ⚡ High Performance: Async/await with connection pooling and retry logic
- 🛡️ Error Handling: Type-safe ToolError for distinguishing retriable and permanent failures
- 🔒 Multi-Tenant Safe: Automatic isolation between concurrent user requests
- 📖 Clear Separation: ApplicationContext for read operations, SignerContext for write operations
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Using LocalEvmSigner
The LocalEvmSigner is the primary concrete implementation for EVM transaction signing:
use LocalEvmSigner;
use EvmNetworkConfig;
use ;
use Arc;
// Create network config
let config = new;
// Create signer from private key
let signer = new?;
// Set up application context
let app_context = new?;
let unified_signer: = new;
app_context.set_signer.await?;
// Now you can use any EVM tool
use send_eth;
let tx_hash = send_eth.await?;
Read Operations with ApplicationContext
Read-only operations (like checking balances) use the ApplicationContext pattern:
use ApplicationContext;
use ;
use ;
use Arc;
async
Write Operations with SignerContext
Write operations (like transfers) require a SignerContext with proper signing capabilities:
use ;
use LocalEvmSigner;
use send_eth;
use ;
use Arc;
use FromStr;
async
DeFi Operations (Uniswap)
use ;
use LocalEvmSigner;
use ;
use Arc;
async
Available Tools
Balance Tools
get_eth_balance- Get ETH balance for an addressget_erc20_balance- Get ERC20 token balance
Transaction Tools
transfer_eth- Transfer ETH to another addresstransfer_erc20- Transfer ERC20 tokensget_transaction_receipt- Get receipt for a transaction
DeFi Tools
get_uniswap_quote- Get swap quote from Uniswap V3perform_uniswap_swap- Execute a token swap on Uniswap
Configuration
Environment Variables
# Convention-based RPC endpoints (RPC_URL_{CHAIN_ID})
RPC_URL_1=https://eth.llamarpc.com # Ethereum (Chain ID: 1)
RPC_URL_137=https://polygon-rpc.com # Polygon (Chain ID: 137)
RPC_URL_42161=https://arb1.arbitrum.io/rpc # Arbitrum (Chain ID: 42161)
RPC_URL_8453=https://base.llamarpc.com # Base (Chain ID: 8453)
# Add any EVM chain by setting RPC_URL_{CHAIN_ID}
# Example: RPC_URL_10=https://optimism.io # Optimism (Chain ID: 10)
# Private key for transactions (required for signing)
EVM_PRIVATE_KEY=0x...
Extensible Chain Support
The EVM tools now support adding new chains without code changes. Simply set an environment variable following the RPC_URL_{CHAIN_ID} convention:
// Any chain with RPC_URL_{ID} set is automatically supported
let supported_chains = get_supported_chains;
println!;
// Check if a specific chain is supported
if is_chain_supported
Supported Networks
- Ethereum Mainnet
- Polygon
- Arbitrum One
- Optimism
- Base
- BNB Smart Chain
- Avalanche C-Chain
- Any EVM-compatible chain with custom RPC
Architecture Patterns
ApplicationContext for Read Operations
Read-only operations use ApplicationContext with a Provider extension:
use ApplicationContext;
use Provider;
// Setup once in your application
let app_context = from_env;
let provider = /* create provider */;
app_context.add_extension;
// Tools use the provider from context
let balance = get_eth_balance.await?;
SignerContext for Write Operations
Write operations require SignerContext with proper signing capabilities:
use ;
// Create signer with private key
let signer = new as ;
// Execute within context
with_signer.await?;
Key Benefits
- Clear Separation: Read vs write operations are clearly distinguished
- Thread Safety: Each async task has its own isolated context
- Multi-Tenant Support: Multiple users can execute operations concurrently
- Type Safety: Operations are type-checked at compile time
- Automatic Context Propagation: Tools automatically access the current context
Type-Safe Chain Access
use SignerContext;
// Get EVM-specific signer (fails if current signer doesn't support EVM)
let evm_signer = current_as_evm.await?;
let address = evm_signer.address;
let chain_id = evm_signer.chain_id;
// Check capabilities before operations
let signer = current.await?;
if signer.supports_evm
Error Handling
All tools use the ToolError pattern to distinguish between retriable and permanent failures:
use ToolError;
use get_eth_balance;
match get_eth_balance.await
Integration with rig
All tools are compatible with the rig framework:
use Agent;
use get_eth_balance_tool;
let agent = builder
.preamble
.tool
.build;
Safety and Security
- Private keys are managed per-client instance, not globally
- All addresses are validated before use
- Automatic nonce management prevents transaction conflicts
- Gas estimation with configurable limits
- Slippage protection for DeFi operations
- Thread-safe client instances can be cloned and shared
License
MIT
Contributing
Contributions are welcome! Please read our contributing guidelines and submit PRs to our GitHub repository.
Support
For issues and questions, please open an issue on GitHub or reach out to the maintainers.