Handle Errors
Catch lending failures and release wallet secrets safely.
This guide explains how to handle operation errors and follow best practices for disposing wallet state.
Operation errors
You can catch failures from supply(), withdraw(), borrow(), and repay() with try/catch:
try {
await aave.supply({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 0n
})
} catch (e) {
console.error('Lending failed:', e.message)
if (e.message.includes('zero')) {
console.log('Amount must be greater than zero')
}
}You can isolate quote failures from quoteSupply() (or the other quote* methods) when you only need an estimate:
try {
const q = await aave.quoteBorrow({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})
console.log('Borrow fee (wei):', q.fee)
} catch (e) {
console.error('Quote failed:', e.message)
}See Rules & Notes for address and amount validation expectations.
Best Practices
You can wipe private keys after lending work by calling dispose() on WalletAccountEvm, or dispose() on WalletManagerEvm:
try {
await aave.supply({
token: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
amount: 1000000n
})
} finally {
account.dispose()
}For ERC-4337 accounts, use dispose() on the smart-account type. Clear references to AaveProtocolEvm when the session ends.