Skip to main content

List User Wallets API

This API endpoint allows authenticated users to retrieve a list of all Ethereum wallets associated with their account, including the primary wallet and any additional wallets.

Endpoint​

GET /api/wallet/list

Authentication​

This endpoint requires authentication. Ensure that the user is logged in and has a valid session.

Request​

This endpoint does not require any parameters in the request body or query string. The user's information is obtained from the authenticated session.

Response​

The API returns a JSON object with the following structure:

{
wallets: Array<{
address: string;
isPrimary: boolean;
}>
}

Where:

  • wallets is an array of wallet objects.

  • Each wallet object contains:

  • address: The Ethereum wallet address.

  • isPrimary: A boolean indicating whether this is the user's primary wallet.

Usage Example

Retrieve the list of wallets for the authenticated user:

const response = await fetch('/api/wallet/list', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json();
console.log(data.wallets); // Array of user's wallets

Error Responses​

The API may return the following error responses:

  • 401 Unauthorized: If the user is not authenticated.
  • 404 Not Found: If the authenticated user's data is not found in the database.
  • 500 Internal Server Error: If there's an error fetching the user's wallet data from the database.
Implementation Details
  1. The endpoint first checks if the user is authenticated using the auth() function.
  2. It then retrieves the user's data from the Firebase Admin database.
  3. The primary wallet is identified and marked with isPrimary: true.
  4. Any additional wallets are extracted from the additionalWallets array in the user data.
  5. All wallets are combined into a single array and returned to the client.
Security Note

Ensure that proper authentication and authorization checks are in place to prevent unauthorized access to user wallet information.

Best Practices
  1. Implement proper error handling in your client-side code to manage potential API errors.
  2. Consider implementing rate limiting to prevent abuse of this endpoint.
  3. Cache the wallet list results for a short period to reduce database load and improve response times.
  4. Regularly audit and clean up unused or inactive additional wallets to maintain data hygiene.
Limitations
  1. This API currently only lists Ethereum-compatible wallets.
  2. The API does not provide balance information for the wallets. To get balance information, you would need to call the balance API for each wallet separately.
  3. The order of additional wallets in the list is not guaranteed and may change between calls.

Stay tuned for updates and feel free to provide feedback for improvements!