Get All UTXOs

The getAllUtxos method retrieves all Unspent Transaction Outputs (UTXOs) for a MNEE address. This method fetches every UTXO associated with the address by automatically paginating through all available results, making it ideal for comprehensive balance calculations and wallet management operations.

Usage

Basic Usage

const address = '1G6CB3Ch4zFkPmuhZzEyChQmrQPfi86qk3';

try {
  const utxos = await mnee.getAllUtxos(address);
  console.log('All UTXOs:', utxos);
  console.log('Total UTXOs found:', utxos.length);

  // Calculate total balance
  const totalBalance = utxos.reduce((sum, utxo) => sum + utxo.data.bsv21.amt, 0);
  console.log('Total balance (atomic):', totalBalance);
  console.log('Total balance (MNEE):', mnee.fromAtomicAmount(totalBalance));
} catch (error) {
  console.error('Error fetching UTXOs:', error.message);
}

Parameters

Parameter
Type
Required
Description

address

string

Yes

The MNEE address to fetch UTXOs for

Response

The method returns a Promise that resolves to an array of MNEEUtxo objects containing all UTXOs for the specified address.

MNEEUtxo Structure

Error Handling

The method handles various error scenarios gracefully:

Performance Considerations

  • Complete Fetch: Retrieves ALL UTXOs for the address, which may take longer for addresses with many UTXOs

  • Automatic Pagination: Uses 25 UTXOs per page and automatically continues until all are fetched

  • Memory Usage: Stores all UTXOs in memory - consider using getUtxos with pagination for very large UTXO sets

  • Network Intensive: Makes multiple API calls for addresses with many UTXOs

Use Cases

  1. Complete Balance Calculation: Get exact total balance including all small UTXOs

  2. Wallet Display: Show all available UTXOs in a wallet interface

  3. UTXO Management: Analyze UTXO distribution and consolidation needs

  4. Audit Operations: Verify all tokens associated with an address

  5. Advanced Transfer Planning: Select optimal UTXOs for complex transactions

Method
Purpose
Performance
Use Case

getAllUtxos

Fetch ALL UTXOs

Slower for large sets

Complete wallet view

getEnoughUtxos

Fetch just enough

Faster for transfers

Pre-transfer validation

getUtxos

Fetch with pagination

Most flexible

Custom pagination needs

Examples

Calculate Complete Balance

UTXO Analysis

Find Specific UTXOs

When NOT to Use

  • Simple balance checks - Use balance method instead

  • Transfer preparation - Use getEnoughUtxos for better performance

  • Large UTXO sets - Consider getUtxos with pagination for better memory management

  • Real-time operations - May be too slow for time-sensitive operations

See Also

Last updated