Wallet Plugin
The Plugin Wallet enables your agent to interact with blockchain wallets. It provides functionality for:
- Fetching token holdings across multiple chains
- Retrieving transaction history for specified wallets
- Supporting multiple blockchain networks via the Covalent API
Installation
-
Install the required package:
Terminal window npm i @iqai/plugin-walletTerminal window pnpm add @iqai/plugin-walletTerminal window yarn add @iqai/plugin-wallet -
Create a
.env
file with the required configuration:Terminal window COVALENT_API_KEY=your-covalent-api-keyWALLET_ADDRESS=your-wallet-addressNever commit your
.env
file or share your API key. Keep your credentials secure to prevent unauthorized access.
Basic Setup
Hereβs a complete example of setting up your agent with the Wallet Plugin:
import { createWalletPlugin } from "@iqai/plugin-wallet";
async function main() { // Initialize Wallet Plugin const walletPlugin = await createWalletPlugin({ covalentApiKey: process.env.COVALENT_API_KEY, walletAddress: process.env.WALLET_ADDRESS, });
// Integrate walletPlugin with your agent or system const agent = new AgentBuilder().withPlugin(walletPlugin).build(); await agent.start();}
main().catch(console.error);
Available Operations
- Holdings Retrieval: Fetch token balances for a wallet
- Transaction History: Retrieve transaction details including timestamps, status, and gas information
Usage Examples
Operation | Example Query |
---|---|
Check Holdings | get my holdings on fraxtal |
Check Holdings | show my tokens on eth-mainnet |
Check Transactions | get my transactions on fraxtal |
Check Transactions | view transaction history of 0x1234...5678 on polygon |
Configuration Options
The Wallet Plugin accepts the following configuration parameters:
interface WalletPluginConfig { covalentApiKey: string; // Covalent API key for blockchain data access walletAddress: string; // Default wallet address}
Error Handling
Always implement proper error handling when using the plugin:
try { const walletPlugin = await createWalletPlugin({ covalentApiKey: process.env.COVALENT_API_KEY, walletAddress: process.env.WALLET_ADDRESS, });} catch (error) { console.error('Failed to initialize Wallet Plugin:', error);}
Best Practices
- β Chain Validation: Verify supported chain names before making requests
- β Address Verification: Ensure wallet addresses are correct and valid
- β Rate Limit Awareness: Handle API rate limits according to Covalent guidelines
- β Security Measures: Keep your API key secure and never expose it publicly
Common Issues and Troubleshooting
- Invalid Chain Name: Ensure youβre using supported chain names as per the Covalent API documentation.
- Missing Wallet Address: If required, provide a valid wallet address.
- API Connection Errors: Check your network connectivity and API key validity.
- Rate Limiting: Be aware of the API rate limits and implement retries or backoff mechanisms.