Skip to main content

Overview

Manage the priority order of registered external wallets. Priority determines the order in which wallets are evaluated for funding transactions. When a transaction is initiated, the platform checks wallets in priority order (1, 2, 3…). The first wallet with sufficient balance and allowance to cover the entire transaction cost is used. Only one wallet funds each transaction - multi-funding is not supported. Lower priority numbers are checked first (priority 1 before priority 2). Use Cases:
  • Control wallet selection order for transactions
  • Optimize for network fees across chains
  • Ensure transactions succeed with fallback wallets
  • Route withdrawals to specific wallets

GET - Retrieve External Wallet Priority

Get the current priority order of all registered external wallets. Wallets are evaluated in this order for transactions, with the first wallet having sufficient balance to cover the entire transaction cost being used. Only one wallet is used per transaction.

Authentication

x-client-key
string
required
Your public API client key
Authorization
string
required
Bearer token for authentication

Response

id
number
Wallet priority identifier
address
string
Blockchain wallet address
currency
string
Currency code (e.g., “usdc”, “usdt”)
network
string
Blockchain network (e.g., “linea”, “ethereum”, “solana”)
priority
number
Current priority value (lower = higher priority)
[
  {
    "id": 551,
    "address": "0x3a11a86cf218c448be519728cd3ac5c741fb3424",
    "currency": "usdc",
    "network": "linea",
    "priority": 1
  },
  {
    "id": 552,
    "address": "0x7b22c1e6f8a4d92b5c3d8e9f1a2b3c4d5e6f7890",
    "currency": "usdt",
    "network": "ethereum",
    "priority": 2
  },
  {
    "id": 553,
    "address": "DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK",
    "currency": "usdc",
    "network": "solana",
    "priority": 3
  }
]
curl -X GET "https://dev.api.baanx.com/v1/wallet/external/priority" \
  -H "x-client-key: YOUR_CLIENT_KEY" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

PUT - Update External Wallet Priority

Update the priority order of external wallets for transaction funding. When a transaction is initiated, wallets are checked sequentially in this order until one with sufficient balance is found to fund the entire transaction. Only one wallet funds each transaction - partial funding from multiple wallets is not supported.

Request Body

wallets
array
required
Array of wallet priority updates

Response

success
boolean
Whether priority update was successful
{
  "success": true
}
curl -X PUT "https://dev.api.baanx.com/v1/wallet/external/priority" \
  -H "x-client-key: YOUR_CLIENT_KEY" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "wallets": [
      {
        "id": 552,
        "priority": 1
      },
      {
        "id": 551,
        "priority": 2
      }
    ]
  }'

Use Cases

Prioritize Low-Fee Networks

async function prioritizeByFees() {
  const wallets = await fetch('/v1/wallet/external/priority')
    .then(r => r.json());

  const feeTiers = {
    'linea': 1,
    'polygon': 2,
    'ethereum': 3
  };

  const reordered = wallets
    .sort((a, b) => (feeTiers[a.network] || 99) - (feeTiers[b.network] || 99))
    .map((w, index) => ({
      id: w.id,
      priority: index + 1
    }));

  await updateExternalWalletPriority(reordered);
  console.log('Prioritized wallets by lowest network fees');
}

Move Specific Wallet to Top

async function moveWalletToTop(targetAddress) {
  const wallets = await fetch('/v1/wallet/external/priority')
    .then(r => r.json());

  const target = wallets.find(w => w.address === targetAddress);

  if (!target) {
    throw new Error('Wallet not found');
  }

  const priorities = [
    { id: target.id, priority: 1 },
    ...wallets
      .filter(w => w.id !== target.id)
      .map((w, index) => ({ id: w.id, priority: index + 2 }))
  ];

  await updateExternalWalletPriority(priorities);
}

await moveWalletToTop('0x3a11a86cf218c448be519728cd3ac5c741fb3424');

Swap Two Wallet Priorities

async function swapPriorities(walletId1, walletId2) {
  const wallets = await fetch('/v1/wallet/external/priority')
    .then(r => r.json());

  const wallet1 = wallets.find(w => w.id === walletId1);
  const wallet2 = wallets.find(w => w.id === walletId2);

  const updates = wallets.map(w => ({
    id: w.id,
    priority:
      w.id === walletId1 ? wallet2.priority :
      w.id === walletId2 ? wallet1.priority :
      w.priority
  }));

  await updateExternalWalletPriority(updates);
}

await swapPriorities(551, 552);

Currency-Based Priority

async function prioritizeByCurrency() {
  const wallets = await fetch('/v1/wallet/external/priority')
    .then(r => r.json());

  const currencyRanking = ['usdc', 'usdt', 'dai'];

  const reordered = wallets
    .sort((a, b) => {
      const rankA = currencyRanking.indexOf(a.currency);
      const rankB = currencyRanking.indexOf(b.currency);
      return (rankA === -1 ? 999 : rankA) - (rankB === -1 ? 999 : rankB);
    })
    .map((w, index) => ({
      id: w.id,
      priority: index + 1
    }));

  await updateExternalWalletPriority(reordered);
}

Important Notes

Single-Wallet Funding: Only ONE wallet funds each transaction. The platform checks wallets in priority order and uses the first one with sufficient balance to cover the ENTIRE transaction cost. If a wallet has insufficient balance, it’s skipped entirely - partial funding from multiple wallets is NOT supported.
Update All Wallets: You must provide priority values for ALL registered external wallets. Partial updates may result in unexpected behavior.
Unique Priorities: Each wallet must have a unique priority value. Duplicate priorities will cause validation errors.
Transaction Failure: If ALL priority wallets have insufficient balance to cover the full transaction cost, the transaction will fail. Ensure at least one wallet always has adequate funds.

Priority Strategy Examples

Balanced Approach

const strategies = {
  balanced: (wallets) => {
    return wallets
      .sort((a, b) => {
        if (a.network === 'linea') return -1;
        if (b.network === 'linea') return 1;
        return a.currency.localeCompare(b.currency);
      })
      .map((w, i) => ({ id: w.id, priority: i + 1 }));
  },

  singlePreferred: (wallets, preferredAddress) => {
    const preferred = wallets.find(w => w.address === preferredAddress);
    return [
      { id: preferred.id, priority: 1 },
      ...wallets
        .filter(w => w.id !== preferred.id)
        .map((w, i) => ({ id: w.id, priority: i + 2 }))
    ];
  },

  networkFirst: (wallets, preferredNetwork) => {
    return wallets
      .sort((a, b) => {
        if (a.network === preferredNetwork && b.network !== preferredNetwork) return -1;
        if (b.network === preferredNetwork && a.network !== preferredNetwork) return 1;
        return 0;
      })
      .map((w, i) => ({ id: w.id, priority: i + 1 }));
  }
};

const wallets = await getExternalWalletPriority();
const newPriorities = strategies.balanced(wallets);
await updateExternalWalletPriority(newPriorities);

Edge Cases

Single Wallet

With only one wallet, priority is always 1:
if (wallets.length === 1) {
  console.log('Only one wallet - priority management not applicable');
}

Validation Before Update

function validatePriorityUpdate(updates) {
  const priorities = updates.map(u => u.priority);
  const ids = updates.map(u => u.id);

  if (new Set(priorities).size !== priorities.length) {
    throw new Error('Duplicate priority values not allowed');
  }

  if (new Set(ids).size !== ids.length) {
    throw new Error('Duplicate wallet IDs not allowed');
  }

  const maxPriority = Math.max(...priorities);
  if (maxPriority > updates.length) {
    console.warn('Priority gaps detected');
  }

  return true;
}