Wagmi Integration
This guide covers using Wagmi-generated contract configurations with AI agents through prompts.
Overview
WalletAgent leverages Wagmi's contract configuration system for AI-powered blockchain interactions:
Contract Configuration Loading: AI agents can load and use Wagmi-generated contract data
Multi-Chain Support: Chain-specific contract deployments accessible through prompts
Prompt Interface: Contract interactions through conversational prompts
AI-Native Workflow: Contract operations without writing code
Wagmi Configuration
Basic Configuration
Create a wagmi.config.ts file in my project root with a Foundry plugin that includes my Counter contract deployed at 0x5FbDB... on Anvil (chain 31337) and 0x742d35... on Sepolia (chain 11155111). Also include an ERC20Token deployed on mainnet and Polygon. Output the generated types to src/generated.ts.What the AI will create:
A Wagmi configuration file with proper imports
Foundry plugin configuration pointing to your contracts directory
Multi-chain deployment addresses for your contracts
Output path for generated TypeScript types
Plugin Options
Foundry Plugin Setup
Hardhat Plugin Setup
ABI Plugin Setup
Code Generation
Generating Types
Alternative prompts:
Generated Output
What you'll get: The generated file will include:
Contract addresses organized by chain ID
Complete contract ABIs with all functions, events, and errors
Function definitions for AI agent contract interactions
Configuration data for all contracts defined in your setup
Expected structure:
Address mappings for multi-chain deployments
ABI definitions with full function signatures
Contract metadata for AI prompt processing
Configuration data for AI agent usage
Loading Contracts
Loading Generated Contracts
What happens:
WalletAgent parses your generated configuration file
Extracts contract ABIs and deployment addresses
Loads all contract definitions for use with AI prompts
Returns summary of loaded contracts and supported chains
Verifying Loaded Contracts
Expected output:
Complete list of available contracts
Deployment addresses for each chain
Chain IDs where each contract is available
Contract names as defined in your Wagmi configuration
Contract Interactions
Type-Safe Reads
Additional examples:
Type-Safe Writes
Additional examples:
Multi-Chain Development
Chain-Specific Deployments
What this enables:
Same contract interface across all supported chains
Automatic address resolution based on current chain
Type-safe interactions regardless of which chain you're on
Seamless switching between development and production environments
Cross-Chain Contract Calls
Alternative multi-chain prompts:
Advanced Configuration
Custom Contract Names
Benefits:
Custom naming for better code readability
Multiple contracts using the same ABI with different names
Clear distinction between similar contracts
Environment-Based Configuration
Use cases:
Development vs production contract addresses
Different configurations for staging environments
Conditional contract inclusion based on environment
Separate test and live contract deployments
Build Integration
Additional build prompts:
Development Workflow
Continuous Generation
Workflow prompts:
Git Integration
Version control considerations:
Generated types should be committed for consistency
Build artifacts should be ignored
Cache directories don't need version control
Contract compilation outputs should be excluded
CI/CD Integration
CI/CD workflow prompts:
Testing with Generated Types
Unit Tests
Test scenario prompts:
Integration Tests
Integration test prompts:
Best Practices
Configuration Management
Key principles:
Environment Separation: Use different configurations for dev/staging/prod
Version Control: Commit generated types for consistency
Automation: Generate types in CI/CD pipelines
Type Safety
Benefits of generated types:
TypeScript validation for function names and parameters
Compile-time error detection for invalid contract calls
Auto-completion for contract methods and events
Type-safe parameter validation
AI agents automatically leverage these types when:
Reading contract functions
Writing to contracts
Validating function parameters
Suggesting available contract methods
Performance
Optimization strategies:
Selective Generation: Only generate contracts you need
Caching: Use build caches to speed up regeneration
Incremental Updates: Only regenerate when contracts change
Troubleshooting
Common Issues
Contract Not Found
Troubleshooting steps:
Verify contract is in Wagmi configuration
Check that types were generated successfully
Ensure contract was loaded into wallet agent
Confirm contract name matches configuration
ABI Mismatch
When to regenerate:
After changing contract source code
When function signatures don't match
After deploying updated contracts
When getting "function not found" errors
Chain Configuration
Common chain issues:
Contract not deployed on current chain
Wrong chain ID in configuration
Missing deployment addresses
Network connection problems
Debugging Tips
Troubleshooting prompts:
Debugging workflow:
Verify Generation: Check generated file exists and contains expected contracts
Check Deployments: Ensure contract addresses are correct for target chains
Validate ABIs: Compare generated ABIs with actual contract interfaces
Test Locally: Use Anvil for consistent local testing
Next Steps
Contract Testing - Testing strategies for Wagmi-integrated contracts
Chain Management - Working with supported chains
API Reference - Complete contract tools reference
Last updated
