Consolidate Balance

Overview

If you have multiple receive addresses for a wallet, you may need to sweep funds to the root address in order to consolidate the balance, enabling withdraw of the maximum funds. The spendable balance of a wallet is the balance of the funds in the root address. The confirmed balance of a wallet is the balance of the root address plus all the receive addresses.

Some blockchains require a minimum balance in a receive address. When you consolidate a wallet, the minimum balance remains in the receive addresses. This results in your spendable balance being slightly less than your confirmed balance.

Consolidating is a transaction from your receive address to your root address. Consolidation transactions follow the normal transaction flow, requiring signatures, approvals, and sending, as outlined in Wallets Overview.

Prerequisites

Steps

  • SDK (account)
  • SDK (UTXO)
  • API (account)
  • API (UTXO)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 const BitGoJS = require('bitgo'); const Promise = require('bluebird'); const bitgo = new BitGoJS.BitGo({ env: 'test' }); const coin = 'talgo'; // Set your wallet id const walletId = ''; // Set your wallet passphrase const walletPassphrase = ''; // Set OTP code const otp = '000000'; // Set your access token here bitgo.authenticateWithAccessToken({ accessToken }); const wallet = await bitgo.coin(coin).wallets().get({ id: walletId }); // Wallet's base address - only address in the wallet that can send funds to other accounts console.log('Base Address:', wallet.coinSpecific().baseAddress); // Confirmed balance - sum of the balance of all the wallet's addresses console.log('Confirmed Balance:', wallet.confirmedBalanceString()); // Spendable balance - balance of the base address console.log('Spendable Balance:', wallet.spendableBalanceString()); // unlock the session for sending funds const unlock = await bitgo.unlock({ otp, duration: 3600 }); if (!unlock) { throw new Error('error unlocking session'); } const consolidationTxes = await wallet.buildAccountConsolidations(); try { for (const unsignedConsolidation of consolidationTxes) { const res = await wallet.sendAccountConsolidation({ walletPassphrase, prebuildTx: unsignedConsolidation }); console.dir(res, { depth: 6 }); } } catch (e) { console.error(e); } );

Step Result

  • account
  • UTXO
1 2 3 { "keyDerivationPath": "string" }

Next Steps

Sign Transactions

See Also