🤖 AI Wallet Management Example
What You'll Learn
Complete examples of using BRDZ SDK's ABSK (AI Blockchain Starter Kit) for natural language wallet operations, conversation management, and automated blockchain interactions.
Prerequisites
- API Key configured
- Authentication setup
- Basic understanding of BRDZ SDK
- User authenticated with valid JWT token
Overview
The ABSK (AI Blockchain Starter Kit) provides dual architecture:
- Manual Operations: Direct SDK method calls
- AI-Powered Operations: Natural language processing
Basic AI Wallet Operations
Simple AI Requests
import brdzSDK from 'anantla_sdk';
class AIWalletManager {
constructor(userId) {
this.userId = userId;
this.cryptoWallet = brdzSDK.cryptoWallet;
}
async processNaturalLanguage(userInput) {
try {
console.log('🤖 Processing:', userInput);
const result = await this.cryptoWallet.processAIIntent({
user_input: userInput,
user_id: this.userId
});
return {
success: true,
message: result.agent_response?.message,
intent_type: result.agent_response?.intent_type,
completed: result.agent_response?.completed,
requires_input: result.agent_response?.requires_input,
execution_result: result.agent_response?.execution_result
};
} catch (error) {
return {
success: false,
error: error.message
};
}
}
// Example AI operations
async createWalletWithAI(description) {
const examples = [
"Create a new wallet called Trading Wallet",
"I need a wallet for DeFi operations",
"Make me a wallet named Savings Account",
"Create a business wallet for payments"
];
return await this.processNaturalLanguage(description);
}
async checkBalanceWithAI(query) {
const examples = [
"Show me my USDC balance on Sepolia",
"What's my total balance across all chains?",
"Check balance in my Trading Wallet",
"How much ETH do I have on Polygon?"
];
return await this.processNaturalLanguage(query);
}
async manageChainWithAI(request) {
const examples = [
"Add Polygon support to my main wallet",
"Enable Sepolia testnet for trading wallet",
"Connect Neon chain to wallet ID 123",
"Remove Amoy chain from my wallet"
];
return await this.processNaturalLanguage(request);
}
}
// Usage Examples
const aiWallet = new AIWalletManager(123);
// Create wallet with natural language
const createResult = await aiWallet.createWalletWithAI(
"Create a new wallet for my NFT collection activities"
);
// Check balances
const balanceResult = await aiWallet.checkBalanceWithAI(
"Show me all my USDC balances across different networks"
);
// Manage chains
const chainResult = await aiWallet.manageChainWithAI(
"Add Polygon Amoy testnet to my main trading wallet"
);
Advanced AI Conversation Flow
class ConversationAIWallet {
constructor(userId) {
this.userId = userId;
this.cryptoWallet = brdzSDK.cryptoWallet;
this.conversationActive = false;
}
async startConversation(initialMessage) {
try {
console.log('🤖 Starting AI conversation...');
// Start fresh conversation
const result = await this.cryptoWallet.conversation.start(
initialMessage,
this.userId
);
this.conversationActive = true;
return this.parseAIResponse(result);
} catch (error) {
throw new Error(`Failed to start conversation: ${error.message}`);
}
}
async continueConversation(message) {
if (!this.conversationActive) {
throw new Error('No active conversation. Start a new one first.');
}
try {
const result = await this.cryptoWallet.conversation.continue(
message,
this.userId
);
return this.parseAIResponse(result);
} catch (error) {
throw new Error(`Conversation failed: ${error.message}`);
}
}
async endConversation() {
if (this.conversationActive) {
await this.cryptoWallet.conversation.end(this.userId);
this.conversationActive = false;
console.log('🤖 Conversation ended');
}
}
parseAIResponse(result) {
const response = this.cryptoWallet.utils.ai.parseResponse(result);
return {
message: response?.message || 'No response',
intent_type: response?.intent_type,
completed: response?.completed || false,
requires_input: response?.requires_input || false,
missing_parameter: response?.missing_parameter,
available_options: response?.available_options || [],
execution_result: response?.execution_result,
conversation_state: response?.conversation_state
};
}
needsMoreInput(result) {
return this.cryptoWallet.utils.ai.needsInput(result);
}
isConversationComplete(result) {
return this.cryptoWallet.utils.ai.isComplete(result);
}
getNextActions(result) {
return this.cryptoWallet.utils.ai.getNextActions(result);
}
async getConversationStatus() {
return await this.cryptoWallet.conversation.getStatus(this.userId);
}
}
// Advanced Conversation Example
async function advancedAIWalletDemo(userId) {
const aiWallet = new ConversationAIWallet(userId);
try {
// Start complex wallet setup conversation
console.log('='.repeat(50));
console.log('🤖 Advanced AI Wallet Management Demo');
console.log('='.repeat(50));
// Step 1: Start conversation
let response = await aiWallet.startConversation(
"I want to set up a complete DeFi trading setup with multiple wallets and cross-chain support"
);
console.log('AI:', response.message);
// Step 2: Continue based on AI response
while (response.requires_input && !response.completed) {
console.log('Next actions:', response.available_options);
// Simulate user providing more details
let userInput;
if (response.missing_parameter === 'wallet_name') {
userInput = "I want to call it DeFi Master Wallet";
} else if (response.missing_parameter === 'chains') {
userInput = "I need Ethereum Sepolia, Polygon Amoy, and Neon EVM support";
} else {
userInput = "Yes, proceed with the setup";
}
console.log('User:', userInput);
response = await aiWallet.continueConversation(userInput);
console.log('AI:', response.message);
// Prevent infinite loops
if (response.conversation_state?.input_required_count > 5) {
console.log('Too many input requests, ending conversation');
break;
}
}
// Step 3: Check final result
if (response.completed) {
console.log('✅ Wallet setup completed!');
console.log('Execution result:', response.execution_result);
}
// End conversation
await aiWallet.endConversation();
} catch (error) {
console.error('❌ Advanced AI demo failed:', error.message);
await aiWallet.endConversation();
}
}
React Component Examples
AI Wallet Chat Component
import React, { useState, useEffect, useRef } from 'react';
import { useSDK } from '../contexts/SDKContext';
interface AIMessage {
id: string;
type: 'user' | 'ai';
message: string;
timestamp: Date;
intent_type?: string;
requires_input?: boolean;
available_options?: string[];
}
const AIWalletChat: React.FC = () => {
const { currentUser, processAIRequest } = useSDK();
const [messages, setMessages] = useState<AIMessage[]>([]);
const [input, setInput] = useState('');
const [loading, setLoading] = useState(false);
const [conversationActive, setConversationActive] = useState(false);
const messagesEndRef = useRef<HTMLDivElement>(null);
useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
}, [messages]);
const addMessage = (message: Omit<AIMessage, 'id' | 'timestamp'>) => {
const newMessage: AIMessage = {
...message,
id: Date.now().toString(),
timestamp: new Date()
};
setMessages(prev => [...prev, newMessage]);
};
const startConversation = async (message: string) => {
if (!message.trim()) return;
addMessage({ type: 'user', message });
setLoading(true);
try {
// Use conversation.start for new conversations
const cryptoWallet = await import('anantla_sdk').then(sdk => sdk.default.cryptoWallet);
const result = await cryptoWallet.conversation.start(message, currentUser!.id);
const aiResponse = cryptoWallet.utils.ai.parseResponse(result);
addMessage({
type: 'ai',
message: aiResponse?.message || 'No response',
intent_type: aiResponse?.intent_type,
requires_input: aiResponse?.requires_input,
available_options: aiResponse?.available_options
});
setConversationActive(true);
} catch (error) {
addMessage({
type: 'ai',
message: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`
});
} finally {
setLoading(false);
setInput('');
}
};
const continueConversation = async (message: string) => {
if (!message.trim()) return;
addMessage({ type: 'user', message });
setLoading(true);
try {
const cryptoWallet = await import('anantla_sdk').then(sdk => sdk.default.cryptoWallet);
const result = await cryptoWallet.conversation.continue(message, currentUser!.id);
const aiResponse = cryptoWallet.utils.ai.parseResponse(result);
addMessage({
type: 'ai',
message: aiResponse?.message || 'No response',
intent_type: aiResponse?.intent_type,
requires_input: aiResponse?.requires_input,
available_options: aiResponse?.available_options
});
// Check if conversation is complete
if (aiResponse?.completed) {
setConversationActive(false);
}
} catch (error) {
addMessage({
type: 'ai',
message: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`
});
} finally {
setLoading(false);
setInput('');
}
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (conversationActive) {
await continueConversation(input);
} else {
await startConversation(input);
}
};
const endConversation = async () => {
try {
const cryptoWallet = await import('anantla_sdk').then(sdk => sdk.default.cryptoWallet);
await cryptoWallet.conversation.end(currentUser!.id);
setConversationActive(false);
addMessage({
type: 'ai',
message: '👋 Conversation ended. Start a new one anytime!'
});
} catch (error) {
console.error('Failed to end conversation:', error);
}
};
const quickActions = [
"Create a new wallet for DeFi trading",
"Show me all my wallet balances",
"Add Polygon support to my main wallet",
"What's my USDC balance on Sepolia?",
"Help me set up cross-chain operations"
];
return (
<div className="ai-wallet-chat">
<div className="chat-header">
<h3>🤖 AI Wallet Assistant</h3>
{conversationActive && (
<button onClick={endConversation} className="end-conversation">
End Chat
</button>
)}
</div>
<div className="chat-messages">
{messages.length === 0 && (
<div className="welcome-message">
<h4>👋 Welcome to AI Wallet Management!</h4>
<p>Ask me anything about your wallets, balances, or blockchain operations.</p>
<div className="quick-actions">
<p><strong>Try these examples:</strong></p>
{quickActions.map((action, index) => (
<button
key={index}
className="quick-action"
onClick={() => setInput(action)}
>
{action}
</button>
))}
</div>
</div>
)}
{messages.map((message) => (
<div
key={message.id}
className={`message ${message.type}`}
>
<div className="message-header">
<span className="message-type">
{message.type === 'user' ? '👤' : '🤖'}
</span>
<span className="message-time">
{message.timestamp.toLocaleTimeString()}
</span>
{message.intent_type && (
<span className="intent-type">
Intent: {message.intent_type}
</span>
)}
</div>
<div className="message-content">
{message.message}
</div>
{message.available_options && message.available_options.length > 0 && (
<div className="available-options">
<p><strong>Available options:</strong></p>
<ul>
{message.available_options.map((option, index) => (
<li key={index}>{option}</li>
))}
</ul>
</div>
)}
{message.requires_input && (
<div className="requires-input">
<em>🔄 Waiting for your response...</em>
</div>
)}
</div>
))}
{loading && (
<div className="message ai">
<div className="message-header">
<span className="message-type">🤖</span>
<span className="message-time">Now</span>
</div>
<div className="message-content">
<div className="typing-indicator">
<span></span>
<span></span>
<span></span>
</div>
Thinking...
</div>
</div>
)}
<div ref={messagesEndRef} />
</div>
<form onSubmit={handleSubmit} className="chat-input">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder={conversationActive
? "Continue the conversation..."
: "Ask about wallets, balances, or operations..."}
disabled={loading}
/>
<button type="submit" disabled={loading || !input.trim()}>
{loading ? '⏳' : '📤'}
</button>
</form>
</div>
);
};
export default AIWalletChat;
AI Wallet Dashboard
import React, { useState, useEffect } from 'react';
import { useSDK } from '../contexts/SDKContext';
interface WalletWithAI {
bw_id: number;
wallet_name: string;
created_at: string;
chains: string[];
balance_summary?: any;
}
const AIWalletDashboard: React.FC = () => {
const { currentUser } = useSDK();
const [wallets, setWallets] = useState<WalletWithAI[]>([]);
const [loading, setLoading] = useState(false);
const [aiSuggestions, setAiSuggestions] = useState<string[]>([]);
useEffect(() => {
loadWalletsWithAI();
generateAISuggestions();
}, []);
const loadWalletsWithAI = async () => {
setLoading(true);
try {
// Use AI to get comprehensive wallet overview
const brdzSDK = await import('anantla_sdk').then(sdk => sdk.default);
const cryptoWallet = brdzSDK.cryptoWallet;
// Get wallets using AI
const aiResult = await cryptoWallet.ai.listWallets(
"Show me detailed overview of all my wallets with balances and chains",
currentUser!.id
);
if (aiResult.execution_result?.wallets) {
setWallets(aiResult.execution_result.wallets);
} else {
// Fallback to manual method
const manualWallets = await cryptoWallet.getUserWallets(currentUser!.id);
setWallets(manualWallets);
}
} catch (error) {
console.error('Failed to load wallets:', error);
} finally {
setLoading(false);
}
};
const generateAISuggestions = async () => {
try {
const brdzSDK = await import('anantla_sdk').then(sdk => sdk.default);
const cryptoWallet = brdzSDK.cryptoWallet;
// Get AI-generated suggestions based on user's current setup
const suggestions = await cryptoWallet.ai.chat(
"Based on my current wallet setup, what are 5 recommended actions I should take?",
currentUser!.id
);
if (suggestions.agent_response?.available_options) {
setAiSuggestions(suggestions.agent_response.available_options);
}
} catch (error) {
console.error('Failed to generate AI suggestions:', error);
}
};
const handleAISuggestion = async (suggestion: string) => {
try {
const brdzSDK = await import('anantla_sdk').then(sdk => sdk.default);
const cryptoWallet = brdzSDK.cryptoWallet;
const result = await cryptoWallet.processAIIntent({
user_input: suggestion,
user_id: currentUser!.id
});
console.log('AI Suggestion executed:', result);
// Reload wallets if operation completed
if (result.agent_response?.completed) {
await loadWalletsWithAI();
}
} catch (error) {
console.error('AI suggestion failed:', error);
}
};
const quickAIActions = [
{
title: "💰 Check All Balances",
prompt: "Show me current balances for all my wallets across all chains"
},
{
title: "⛓️ Add Chain Support",
prompt: "Add Polygon Amoy testnet support to my main wallet"
},
{
title: "📊 Portfolio Analysis",
prompt: "Analyze my crypto portfolio and suggest optimizations"
},
{
title: "🔄 Cross-Chain Setup",
prompt: "Help me set up cross-chain transfer capabilities"
}
];
return (
<div className="ai-wallet-dashboard">
<div className="dashboard-header">
<h2>🤖 AI-Powered Wallet Dashboard</h2>
<button onClick={loadWalletsWithAI} disabled={loading}>
{loading ? '⏳ Loading...' : '🔄 Refresh'}
</button>
</div>
{/* AI Suggestions Section */}
<section className="ai-suggestions">
<h3>💡 AI Recommendations</h3>
<div className="suggestions-grid">
{aiSuggestions.map((suggestion, index) => (
<div key={index} className="suggestion-card">
<p>{suggestion}</p>
<button onClick={() => handleAISuggestion(suggestion)}>
✨ Execute
</button>
</div>
))}
</div>
</section>
{/* Quick AI Actions */}
<section className="quick-actions">
<h3>⚡ Quick AI Actions</h3>
<div className="actions-grid">
{quickAIActions.map((action, index) => (
<button
key={index}
className="action-card"
onClick={() => handleAISuggestion(action.prompt)}
>
<span className="action-title">{action.title}</span>
<span className="action-prompt">{action.prompt}</span>
</button>
))}
</div>
</section>
{/* Wallets Overview */}
<section className="wallets-overview">
<h3>👜 Your Wallets ({wallets.length})</h3>
{loading ? (
<div className="loading-state">
<div className="spinner">⏳</div>
<p>AI is analyzing your wallets...</p>
</div>
) : (
<div className="wallets-grid">
{wallets.map((wallet) => (
<div key={wallet.bw_id} className="wallet-card-ai">
<div className="wallet-header">
<h4>{wallet.wallet_name}</h4>
<span className="wallet-id">#{wallet.bw_id}</span>
</div>
<div className="wallet-info">
<p><strong>Chains:</strong> {wallet.chains?.length || 0}</p>
<p><strong>Created:</strong> {new Date(wallet.created_at).toLocaleDateString()}</p>
</div>
{wallet.balance_summary && (
<div className="balance-summary">
<h5>💰 Balance Summary</h5>
<pre>{JSON.stringify(wallet.balance_summary, null, 2)}</pre>
</div>
)}
<div className="wallet-actions">
<button onClick={() => handleAISuggestion(`Show balance for wallet ${wallet.wallet_name}`)}>
💰 Check Balance
</button>
<button onClick={() => handleAISuggestion(`Add new chain to wallet ${wallet.wallet_name}`)}>
⛓️ Add Chain
</button>
</div>
</div>
))}
</div>
)}
{wallets.length === 0 && !loading && (
<div className="empty-state">
<h4>🎯 No Wallets Found</h4>
<p>Let AI help you create your first wallet!</p>
<button onClick={() => handleAISuggestion("Create my first crypto wallet for general use")}>
🚀 Create First Wallet with AI
</button>
</div>
)}
</section>
</div>
);
};
export default AIWalletDashboard;
Advanced AI Features
AI Session Management
class AISessionManager {
constructor(userId) {
this.userId = userId;
this.cryptoWallet = brdzSDK.cryptoWallet;
}
async checkAIHealth() {
try {
const health = await this.cryptoWallet.checkAIHealth();
return {
healthy: health.success,
service_status: health.service_status,
fully_configured: health.service_status?.fully_configured,
environment_checks: health.service_status?.environment_checks
};
} catch (error) {
return {
healthy: false,
error: error.message
};
}
}
async hasActiveSession() {
try {
const status = await this.cryptoWallet.conversation.getStatus(this.userId);
return status.hasActive;
} catch (error) {
return false;
}
}
async clearAllSessions() {
try {
await this.cryptoWallet.clearAISession(this.userId);
console.log('✅ All AI sessions cleared');
} catch (error) {
console.error('❌ Failed to clear sessions:', error.message);
}
}
async validateAIService() {
const health = await this.checkAIHealth();
if (!health.healthy) {
throw new Error('AI service is not available');
}
if (!health.fully_configured) {
console.warn('⚠️ AI service partially configured');
console.log('Environment checks:', health.environment_checks);
}
return health;
}
}
// Usage
const aiSession = new AISessionManager(123);
// Validate before using AI features
const health = await aiSession.validateAIService();
console.log('AI Service Status:', health);
// Check for existing sessions
const hasActive = await aiSession.hasActiveSession();
if (hasActive) {
console.log('Found active AI session');
}
Batch AI Operations
class BatchAIOperations {
constructor(userId) {
this.userId = userId;
this.cryptoWallet = brdzSDK.cryptoWallet;
}
async executeBatchOperations(operations) {
const results = [];
for (const operation of operations) {
try {
console.log(`🤖 Processing: ${operation}`);
const result = await this.cryptoWallet.processAIIntent({
user_input: operation,
user_id: this.userId
});
results.push({
operation,
success: true,
result: result.agent_response
});
// Wait between operations to avoid rate limits
await new Promise(resolve => setTimeout(resolve, 1000));
} catch (error) {
results.push({
operation,
success: false,
error: error.message
});
}
}
return results;
}
async setupCompleteWalletSystem() {
const operations = [
"Create a wallet named Primary Trading Wallet",
"Create a wallet named DeFi Savings Wallet",
"Add Ethereum Sepolia support to Primary Trading Wallet",
"Add Polygon Amoy support to Primary Trading Wallet",
"Add Neon EVM support to DeFi Savings Wallet",
"Check balances for all wallets"
];
console.log('🚀 Starting complete wallet system setup...');
const results = await this.executeBatchOperations(operations);
console.log('📊 Batch Operation Results:');
results.forEach((result, index) => {
console.log(`${index + 1}. ${result.operation}`);
console.log(` Status: ${result.success ? '✅ Success' : '❌ Failed'}`);
if (result.error) {
console.log(` Error: ${result.error}`);
}
});
return results;
}
}
// Usage
const batchAI = new BatchAIOperations(123);
const setupResults = await batchAI.setupCompleteWalletSystem();
Styling for AI Components
/* AI Wallet Chat Styles */
.ai-wallet-chat {
display: flex;
flex-direction: column;
height: 600px;
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
}
.chat-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
background: #f8f9fa;
border-bottom: 1px solid #ddd;
}
.end-conversation {
padding: 6px 12px;
background: #dc3545;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.chat-messages {
flex: 1;
overflow-y: auto;
padding: 15px;
}
.welcome-message {
text-align: center;
padding: 20px;
color: #666;
}
.quick-actions {
margin-top: 20px;
}
.quick-action {
display: block;
width: 100%;
margin: 5px 0;
padding: 10px;
text-align: left;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
.quick-action:hover {
background: #e9ecef;
}
.message {
margin-bottom: 20px;
padding: 12px;
border-radius: 8px;
}
.message.user {
background: #007bff;
color: white;
margin-left: 20%;
}
.message.ai {
background: #f8f9fa;
border: 1px solid #ddd;
margin-right: 20%;
}
.message-header {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
font-size: 12px;
color: #666;
}
.message.user .message-header {
color: rgba(255, 255, 255, 0.8);
}
.intent-type {
background: #28a745;
color: white;
padding: 2px 6px;
border-radius: 12px;
font-size: 10px;
}
.available-options {
margin-top: 10px;
padding: 10px;
background: rgba(0, 123, 255, 0.1);
border-radius: 4px;
}
.available-options ul {
margin: 5px 0 0 0;
padding-left: 20px;
}
.requires-input {
margin-top: 10px;
color: #ffc107;
font-style: italic;
}
.typing-indicator {
display: inline-flex;
align-items: center;
gap: 4px;
margin-right: 8px;
}
.typing-indicator span {
width: 6px;
height: 6px;
background: #666;
border-radius: 50%;
animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
.chat-input {
display: flex;
padding: 15px;
border-top: 1px solid #ddd;
background: #f8f9fa;
}
.chat-input input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
margin-right: 10px;
}
.chat-input button {
padding: 10px 15px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
/* AI Dashboard Styles */
.ai-wallet-dashboard {
padding: 20px;
}
.ai-suggestions {
margin-bottom: 30px;
}
.suggestions-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-top: 15px;
}
.suggestion-card {
padding: 15px;
border: 1px solid #ddd;
border-radius: 8px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.suggestion-card button {
margin-top: 10px;
padding: 6px 12px;
background: rgba(255, 255, 255, 0.2);
color: white;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 4px;
cursor: pointer;
}
.actions-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 15px;
}
.action-card {
display: flex;
flex-direction: column;
padding: 15px;
text-align: left;
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
}
.action-card:hover {
background: #e9ecef;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.action-title {
font-weight: bold;
margin-bottom: 5px;
}
.action-prompt {
font-size: 12px;
color: #666;
}
.wallet-card-ai {
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.wallet-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.wallet-id {
background: #6c757d;
color: white;
padding: 2px 6px;
border-radius: 12px;
font-size: 12px;
}
.wallet-actions {
display: flex;
gap: 10px;
margin-top: 15px;
}
.wallet-actions button {
flex: 1;
padding: 8px 12px;
background: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.loading-state {
text-align: center;
padding: 40px;
color: #666;
}
.spinner {
font-size: 48px;
animation: spin 2s linear infinite;
margin-bottom: 15px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
Best Practices
Error Handling for AI Operations
const handleAIWithRetry = async (operation, maxRetries = 3) => {
let lastError;
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const result = await brdzSDK.cryptoWallet.processAIIntent({
user_input: operation,
user_id: userId
});
return result;
} catch (error) {
lastError = error;
console.warn(`Attempt ${attempt} failed:`, error.message);
if (attempt < maxRetries) {
// Wait before retry with exponential backoff
const delay = Math.pow(2, attempt) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
}
}
}
throw new Error(`AI operation failed after ${maxRetries} attempts: ${lastError.message}`);
};
AI Response Validation
const validateAIResponse = (result) => {
const response = brdzSDK.cryptoWallet.utils.ai.parseResponse(result);
if (!response) {
throw new Error('Invalid AI response format');
}
if (response.cancelled) {
throw new Error('AI operation was cancelled');
}
if (response.requires_input && !response.available_options?.length) {
throw new Error('AI requires input but no options provided');
}
return response;
};
Next Steps
You've learned comprehensive AI wallet management with BRDZ SDK:
✅ Natural Language Processing - Convert user intent to wallet operations
✅ Conversation Management - Handle complex multi-step interactions
✅ React Integration - Build AI-powered wallet interfaces
✅ Session Management - Control AI conversation flows
✅ Batch Operations - Execute multiple AI operations efficiently
Continue Learning
- Payment Processing - AI-powered commerce flows
- Cross-Chain Operations - Multi-blockchain with AI
- SDK Reference - Complete ABSK documentation
Need Help?
If you encounter issues:
- Email: contact@anantla.com
- Contact: BRDZ Contact Form