# Consolidate Account Balance

Source: https://developers.bitgo.com/docs/wallets-consolidate

## Overview

A consolidation is a transaction that transfers assets from receive addresses to the base address of a wallet.

For account-based assets, the spendable balance of a wallet is the balance of the assets in the base address. The spendable balance is the total amount available for withdrawal. The confirmed balance is the balance of the base address plus all the receive addresses. If a wallet has multiple receive addresses, you can obtain the maximum withdrawal amount by consolidating the balances from the receive addresses to the base address.

Manual consolidations are required for account based assets that aren't on Ethereum Virtual Machine (EVM) blockchains. For EVM wallets, BitGo can enable automatic consolidations. To learn about automatic consolidations for EVM wallets, see [Consolidations](/docs/consolidations).

### How it Works

Consolidations are a type of transaction request. A single consolidation request can consolidate multiple receive addresses. Most networks can consolidate up to 750 addresses per consolidation request.

Each receive address in a consolidation request creates a unique transaction. For example, if you consolidate a wallet with 10 receive addresses in a single consolidation request, BitGo creates 10 on-chain transactions.

Consolidations are also single asset transactions. If a wallet has a variety of assets in the receive addresses, you must consolidate each asset in a separate consolidation request.

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.

> 📘 **Note:** Solana stands out from other blockchains in how it handles consolidations. For Solana wallets, Solana limits consolidations to just 25 receive addresses per consolidation. However, Solana wallets are capable of consolidating up to eight different assets from a receive address in a consolidation request, significantly reducing transaction costs.

Either the gas tank or the receive address pays the fee for a consolidation transaction. You can view the fee source for each asset in [Consolidations](/docs/consolidations). You can learn more about asset-specific requirements for consolidations in the [Blockchain References](https://assets.bitgo.com/coins).

### Simple or Manual

Similar to withdrawing, consolidating has two different flows that you can use depending on your use case. The simple flow uses either Express or the the JavaScript SDK. In the simple flow, you build, sign, and send the the consolidation transaction all in 1 step. The manual flow uses either REST endpoints or the JavaScript SDK to build the consolidation transaction, and then sign and send it in separate calls.

This page documents both flows. Select the button below for the flow that works best for you:

<Tabs>
<Tab title="Simple">
## Prerequisites

* [Get Started](/docs/get-started-intro)
* [Create Wallets](/docs/wallets-create-wallets)
* [Create Addresses](/docs/wallets-create-addresses)

## 1. (Optional) Check Consolidation Requirements

Determine if your wallet requires consolidations.

>Endpoint: [Get Wallet by ID](/reference/v2walletgetbyid)

```shell cURL
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X GET \
  https://app.bitgo-test.com/api/v2/wallet/$WALLET_ID \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
```

#### Step Result

The response shows either `"needsConsolidation": true` or `"needsConsolidation": false`.

```shell JSON
{
  "allowBackupKeySigning": true,
  "approvalsRequired": 1,
  "coin": "tbtc4",
  ...
  ...
  ...
    "needsConsolidation": true,
    "tokenConsolidationState": null,
    "tokenAddress": null
  }
```

## 2. Build, Sign, and Send Consolidation

Modify the following code to build, sing, and send a consolidation transaction, all in 1 step.

>Endpoint: [Consolidate Account (Simple)](/reference/expresswalletconsolidateaccount)

```shell cURL
export BITGO_EXPRESS_HOST="<YOUR_LOCAL_HOST>"
export COIN="<ASSET_ID>"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export WALLET_PASSPHRASE="<WALLET_PASSPHRASE>"

curl -X POST \
  http://$BITGO_EXPRESS_HOST/api/v2/$COIN/wallet/$WALLET_ID/consolidateAccount \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
  "walletPassphrase": "'"$WALLET_PASSPHRASE"'"
}'
```
```js JavaScript
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 assets 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 assets
  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

<Tabs>
<Tab title="Custody">
If the transaction requires admin approval, it remains in a pending approval status until receiving final approval. If approval isn't required, you receive a calendar invitation by email to schedule video ID verification with a BitGo operator.
</Tab>
<Tab title="Self-Custody">
<br>
</br>
Your base address receives all available assets from the receive address, maximizing your spendable balance.

```json JSON
{
  "success": [
    {
      "transfer": {
        "entries": [
          {
            "address": "2MTMBrkZ8ufANXEspAygYidLdq23DuchgUbAnVhM5WJ2",
            "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
            "value": -552864,
            "valueString": "-552864"
          },
          {
            "address": "goS1SabSeeAkSGYDTKAxAtxGDuhVhvdow9hzrAmSs7i",
            "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
            "value": 547864,
            "valueString": "547864"
          }
        ],
        "id": "664cb91bad992f4616883304a7fc0474",
        "coin": "tsol",
        "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
        "walletType": "hot",
        "enterprise": "62c5ae8174ac860007aff138a2d74df7",
        "txid": "3HQgnz8CvzY5nNGDZVgxWjP7iW6E4w2PiDJ5AmVWdrMpMCPYR2th8THrXNG8iRYn1uhqJBCcSusPKaduqizfbCDm",
        "txidType": "transactionHash",
        "txRequestId": "ea456e38-ed16-44dd-ae07-95ea2d11fc52",
        "height": 999999999,
        "heightId": "999999999-664cb91bad992f4616883304a7fc0474",
        "date": "2024-05-21T15:09:15.345Z",
        "type": "send",
        "value": -5000,
        "valueString": "-5000",
        "intendedValueString": "-5000",
        "baseValue": 0,
        "baseValueString": "0",
        "baseValueWithoutFees": 0,
        "baseValueWithoutFeesString": "0",
        "feeString": "5000",
        "payGoFee": 0,
        "payGoFeeString": "0",
        "usd": -0.00088675,
        "usdRate": 177.35,
        "state": "signed",
        "instant": false,
        "isReward": false,
        "isUnlock": false,
        "isFee": false,
        "tags": [
          "663bd7b6f7d26f5528c280b7ef3f283c",
          "62c5ae8174ac860007aff138a2d74df7"
        ],
        "history": [
          {
            "date": "2024-05-21T15:09:15.385Z",
            "action": "commented",
            "comment": "Address balance consolidation"
          },
          { "date": "2024-05-21T15:09:15.345Z", "action": "signed" },
          {
            "date": "2024-05-21T15:09:15.088Z",
            "user": "62ab90e06dfda30007974f0a52a12995",
            "action": "created"
          }
        ],
        "signedDate": "2024-05-21T15:09:15.345Z",
        "comment": "Address balance consolidation",
        "metadata": [],
        "commentedTime": "2024-05-21T15:09:15.385Z",
        "signedTime": "2024-05-21T15:09:15.345Z",
        "createdTime": "2024-05-21T15:09:15.088Z",
        "consolidateId": "664cb910334efb3022281f91c04ab1cd"
      },
      "txid": "3HQgnz8CvzY5nNGDZVgxWjP7iW6E4w2PiDJ5AmVWdrMpMCPYR2th8THrXNG8iRYn1uhqJBCcSusPKaduqizfbCDm",
      "tx": "AXIvGBmFU1kcxtS2OYkgTyq6mNaNZXyBJbc2KXRk+IcTUnZ19AELipFAoTrXWQ+S4Z9R5IGi2SpTwYbtJ/9+dgABAAEDFBkYTpHBo1CjPmnPcBEV4prWe5qcrLJsnSPncQFFGE8KMibEyVdRKDQLyxt8RE+Dnc/cWvkd2t5kq17sfnYKlQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAw/V2CP68vtBg9DLRZD5VjyAGKE4p4UzeMdsSPuGMQBAgIAAQwCAAAAGFwIAAAAAAA=",
      "status": "signed"
    },
    {
      "transfer": {
        "entries": [
          {
            "address": "2GqoXzwbrMzsihaBFJ7rqv2Wx97TZFoeYXGgtUXfB5rV",
            "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
            "value": -552864,
            "valueString": "-552864"
          },
          {
            "address": "goS1SabSeeAkSGYDTKAxAtxGDuhVhvdow9hzrAmSs7i",
            "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
            "value": 547864,
            "valueString": "547864"
          }
        ],
        "id": "664cb925115835bc0705c77dcb9c31f3",
        "coin": "tsol",
        "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
        "walletType": "hot",
        "enterprise": "62c5ae8174ac860007aff138a2d74df7",
        "txid": "4jTuXye727WJmbxZbj2FGvmyMC7Eaz5QZJm4Ltne66ugt8ZpaH3EKmrisPccjWCpMhZ65tNAM2sq3MpxEeNyLtj7",
        "txidType": "transactionHash",
        "txRequestId": "fa888ab0-b77d-42a5-b739-deb5188e51fd",
        "height": 999999999,
        "heightId": "999999999-664cb925115835bc0705c77dcb9c31f3",
        "date": "2024-05-21T15:09:25.508Z",
        "type": "send",
        "value": -5000,
        "valueString": "-5000",
        "intendedValueString": "-5000",
        "baseValue": 0,
        "baseValueString": "0",
        "baseValueWithoutFees": 0,
        "baseValueWithoutFeesString": "0",
        "feeString": "5000",
        "payGoFee": 0,
        "payGoFeeString": "0",
        "usd": -0.00088675,
        "usdRate": 177.35,
        "state": "signed",
        "instant": false,
        "isReward": false,
        "isUnlock": false,
        "isFee": false,
        "tags": [
          "663bd7b6f7d26f5528c280b7ef3f283c",
          "62c5ae8174ac860007aff138a2d74df7"
        ],
        "history": [
          {
            "date": "2024-05-21T15:09:25.538Z",
            "action": "commented",
            "comment": "Address balance consolidation"
          },
          { "date": "2024-05-21T15:09:25.507Z", "action": "signed" },
          {
            "date": "2024-05-21T15:09:25.149Z",
            "user": "62ab90e06dfda30007974f0a52a12995",
            "action": "created"
          }
        ],
        "signedDate": "2024-05-21T15:09:25.507Z",
        "comment": "Address balance consolidation",
        "metadata": [],
        "commentedTime": "2024-05-21T15:09:25.538Z",
        "signedTime": "2024-05-21T15:09:25.507Z",
        "createdTime": "2024-05-21T15:09:25.149Z",
        "consolidateId": "664cb910334efb3022281f91c04ab1cd"
      },
      "txid": "4jTuXye727WJmbxZbj2FGvmyMC7Eaz5QZJm4Ltne66ugt8ZpaH3EKmrisPccjWCpMhZ65tNAM2sq3MpxEeNyLtj7",
      "tx": "AbqrlR3L8qoQGDlUnooBjVXBLyRoLi9rXznrrYLLqN9CDVHhKt/YSxIhrze9ng+1azIQDVftZLwD+CawRjLKRw4BAAEDEuqUfC0SW8xbjWksisdw1dxfwRf14h9vSLzSrrFOS7YKMibEyVdRKDQLyxt8RE+Dnc/cWvkd2t5kq17sfnYKlQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArNS3mxnrCl9ZCCnOs/2JXWZvs/Y+GG6Dywi7P3UNdMABAgIAAQwCAAAAGFwIAAAAAAA=",
      "status": "signed"
    },
    {
      "transfer": {
        "entries": [
          {
            "address": "AFzvP594RVzU6WiGyDHwZTmRRSLb8pw2RsHzkksxBP2B",
            "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
            "value": -552864,
            "valueString": "-552864"
          },
          {
            "address": "goS1SabSeeAkSGYDTKAxAtxGDuhVhvdow9hzrAmSs7i",
            "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
            "value": 547864,
            "valueString": "547864"
          }
        ],
        "id": "664cb93117afd10ac8b0383829db00ed",
        "coin": "tsol",
        "wallet": "663bd7b6f7d26f5528c280b7ef3f283c",
        "walletType": "hot",
        "enterprise": "62c5ae8174ac860007aff138a2d74df7",
        "txid": "2M57pzr6p9KUaaEEMHpGTTGU5fzyVbGyKuETkYV7uXvbCv25wecCYhmDk9Rm3D1H47SKpJiqwFN6rr5W6uuhaVwu",
        "txidType": "transactionHash",
        "txRequestId": "1c4a88bb-7740-44e4-9d08-38c136df7f8e",
        "height": 999999999,
        "heightId": "999999999-664cb93117afd10ac8b0383829db00ed",
        "date": "2024-05-21T15:09:37.235Z",
        "type": "send",
        "value": -5000,
        "valueString": "-5000",
        "intendedValueString": "-5000",
        "baseValue": 0,
        "baseValueString": "0",
        "baseValueWithoutFees": 0,
        "baseValueWithoutFeesString": "0",
        "feeString": "5000",
        "payGoFee": 0,
        "payGoFeeString": "0",
        "usd": -0.00088675,
        "usdRate": 177.35,
        "state": "signed",
        "instant": false,
        "isReward": false,
        "isUnlock": false,
        "isFee": false,
        "tags": [
          "663bd7b6f7d26f5528c280b7ef3f283c",
          "62c5ae8174ac860007aff138a2d74df7"
        ],
        "history": [
          {
            "date": "2024-05-21T15:09:37.264Z",
            "action": "commented",
            "comment": "Address balance consolidation"
          },
          { "date": "2024-05-21T15:09:37.234Z", "action": "signed" },
          {
            "date": "2024-05-21T15:09:37.009Z",
            "user": "62ab90e06dfda30007974f0a52a12995",
            "action": "created"
          }
        ],
        "signedDate": "2024-05-21T15:09:37.234Z",
        "comment": "Address balance consolidation",
        "metadata": [],
        "commentedTime": "2024-05-21T15:09:37.264Z",
        "signedTime": "2024-05-21T15:09:37.234Z",
        "createdTime": "2024-05-21T15:09:37.009Z",
        "consolidateId": "664cb910334efb3022281f91c04ab1cd"
      },
      "txid": "2M57pzr6p9KUaaEEMHpGTTGU5fzyVbGyKuETkYV7uXvbCv25wecCYhmDk9Rm3D1H47SKpJiqwFN6rr5W6uuhaVwu",
      "tx": "AUNTUYXexJbz6RjxX1Ga14qwGTPwPd5YpLzBi/4DtY9MBC9Jc43khC5+61KJVP/vXoo6XuYKQWXifyiZfmb15QgBAAEDiZDN7k1FUnqrrJBWaXhRop9j1qK90E28ahsOO6ki79wKMibEyVdRKDQLyxt8RE+Dnc/cWvkd2t5kq17sfnYKlQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5cmAUpykyqMWtL78+NOLu+WCq+q675rFDp0e/Hf2OAIBAgIAAQwCAAAAGFwIAAAAAAA=",
      "status": "signed"
    }
  ],
  "failure": []
}
```
</Tab>
</Tabs>
</Tab>
<Tab title="Manual">
## Prerequisites

* [Get Started](/docs/get-started-intro)
* [Create Wallets](/docs/wallets-create-wallets)
* [Create Addresses](/docs/wallets-create-addresses)

## 1. (Optional) Check Consolidation Requirements

Determine if your wallet requires consolidations.

>Endpoint: [Get Wallet by ID](/reference/v2walletgetbyid)

```shell cURL
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X GET \
  https://app.bitgo-test.com/api/v2/wallet/$WALLET_ID \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
```

#### Step Result

The response shows either `"needsConsolidation": true` or `"needsConsolidation": false`.

```shell JSON
{
  "allowBackupKeySigning": true,
  "approvalsRequired": 1,
  "coin": "tbtc4",
  ...
  ...
  ...
    "needsConsolidation": true,
    "tokenConsolidationState": null,
    "tokenAddress": null
  }
```

## 2. Build Consolidation

Begin the manual flow by building a consolidation transaction.

>Endpoint: [Consolidate Account (Manual)](/reference/v2walletconsolidateaccountbuild)

```shell cURL
export COIN="<ASSET_ID>"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/v2/$COIN/wallet/$WALLET_ID/consolidateAccount/build \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```
```js JavaScript
let params = {
  consolidateAddresses: [
    'BVMEUTF37WNEQ6GYCZISRFHGLEMOKT5OCPPTTJXVED6JBSXKF6YJJRZRI4',
    '7ITFVRNTLUHLD4F2PIIYXXIQOAJAPRGMA7JHSN3SFH2BACLK7WM6CHT524',
  ],
};
wallet.consolidateAccount(params).then(function (transactions) {
  // print generated transactions for signing
  console.dir(transaction);
});
```

#### Step Result

```json JSON
[
  {
    "txRequestId": "9e4ca1e6-4b61-4a24-97cf-b105f6b9e5c2",
    "walletId": "663bd7b6f7d26f5528c280b7",
    "txHex": "0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001031419184e91c1a350a33e69cf701115e29ad67b9a9cacb26c9d23e7710145184f0a3226c4c9575128340bcb1b7c444f839dcfdc5af91ddade64ab5eec7e760a950000000000000000000000000000000000000000000000000000000000000000b4fb04953a8154b3cbcd37ec9d7a24897405d5642b41d24f38a4a09a8b99b5da01020200010c02000000b82e0f0000000000",
    "feeInfo": { "fee": 5000, "feeString": "5000" },
    "txInfo": {
      "minerFee": "5000",
      "spendAmount": "995000",
      "spendAmounts": [{ "coinName": "tsol", "amountString": "995000" }],
      "payGoFee": "0",
      "outputs": [
        {
          "address": "goS1SabSeeAkSGYDTKAxAtxGDuhVhvdow9hzrAmSs7i",
          "value": 995000,
          "wallet": "663bd7b6f7d26f5528c280b7",
          "wallets": ["663bd7b6f7d26f5528c280b7"],
          "enterprise": "62c5ae8174ac860007aff138",
          "enterprises": ["62c5ae8174ac860007aff138"],
          "valueString": "995000",
          "coinName": "tsol"
        }
      ],
      "inputs": [
        {
          "value": 995000,
          "address": "2MTMBrkZ8ufANXEspAygYidLdq23DuchgUbAnVhM5WJ2",
          "valueString": "995000"
        },
        {
          "value": 5000,
          "address": "2MTMBrkZ8ufANXEspAygYidLdq23DuchgUbAnVhM5WJ2",
          "valueString": "5000"
        }
      ],
      "type": "Send"
    },
    "consolidateId": "664cc50265514f8953bbeb8b7a97d284",
    "coin": "tsol"
  },
  {
    "txRequestId": "8a14a584-1c18-4f4e-a43f-86b069e6701d",
    "walletId": "663bd7b6f7d26f5528c280b7",
    "txHex": "01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010312ea947c2d125bcc5b8d692c8ac770d5dc5fc117f5e21f6f48bcd2aeb14e4bb60a3226c4c9575128340bcb1b7c444f839dcfdc5af91ddade64ab5eec7e760a950000000000000000000000000000000000000000000000000000000000000000b4fb04953a8154b3cbcd37ec9d7a24897405d5642b41d24f38a4a09a8b99b5da01020200010c02000000b82e0f0000000000",
    "feeInfo": { "fee": 5000, "feeString": "5000" },
    "txInfo": {
      "minerFee": "5000",
      "spendAmount": "995000",
      "spendAmounts": [{ "coinName": "tsol", "amountString": "995000" }],
      "payGoFee": "0",
      "outputs": [
        {
          "address": "goS1SabSeeAkSGYDTKAxAtxGDuhVhvdow9hzrAmSs7i",
          "value": 995000,
          "wallet": "663bd7b6f7d26f5528c280b7",
          "wallets": ["663bd7b6f7d26f5528c280b7"],
          "enterprise": "62c5ae8174ac860007aff138",
          "enterprises": ["62c5ae8174ac860007aff138"],
          "valueString": "995000",
          "coinName": "tsol"
        }
      ],
      "inputs": [
        {
          "value": 995000,
          "address": "2GqoXzwbrMzsihaBFJ7rqv2Wx97TZFoeYXGgtUXfB5rV",
          "valueString": "995000"
        },
        {
          "value": 5000,
          "address": "2GqoXzwbrMzsihaBFJ7rqv2Wx97TZFoeYXGgtUXfB5rV",
          "valueString": "5000"
        }
      ],
      "type": "Send"
    },
    "consolidateId": "664cc50265514f8953bbeb8b7a97d284",
    "coin": "tsol"
  },
  {
    "txRequestId": "aa70f489-b8a8-4ad1-828d-7ed5f59a4ce7",
    "walletId": "663bd7b6f7d26f5528c280b7",
    "txHex": "0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001038990cdee4d45527aabac9056697851a29f63d6a2bdd04dbc6a1b0e3ba922efdc0a3226c4c9575128340bcb1b7c444f839dcfdc5af91ddade64ab5eec7e760a950000000000000000000000000000000000000000000000000000000000000000b4fb04953a8154b3cbcd37ec9d7a24897405d5642b41d24f38a4a09a8b99b5da01020200010c02000000b82e0f0000000000",
    "feeInfo": { "fee": 5000, "feeString": "5000" },
    "txInfo": {
      "minerFee": "5000",
      "spendAmount": "995000",
      "spendAmounts": [{ "coinName": "tsol", "amountString": "995000" }],
      "payGoFee": "0",
      "outputs": [
        {
          "address": "goS1SabSeeAkSGYDTKAxAtxGDuhVhvdow9hzrAmSs7i",
          "value": 995000,
          "wallet": "663bd7b6f7d26f5528c280b7",
          "wallets": ["663bd7b6f7d26f5528c280b7"],
          "enterprise": "62c5ae8174ac860007aff138",
          "enterprises": ["62c5ae8174ac860007aff138"],
          "valueString": "995000",
          "coinName": "tsol"
        }
      ],
      "inputs": [
        {
          "value": 995000,
          "address": "AFzvP594RVzU6WiGyDHwZTmRRSLb8pw2RsHzkksxBP2B",
          "valueString": "995000"
        },
        {
          "value": 5000,
          "address": "AFzvP594RVzU6WiGyDHwZTmRRSLb8pw2RsHzkksxBP2B",
          "valueString": "5000"
        }
      ],
      "type": "Send"
    },
    "consolidateId": "664cc50265514f8953bbeb8b7a97d284",
    "coin": "tsol"
  }
]
```

## 3. Sign Consolidation

Signing transactions from a MPC wallet is a 3-step process, unless you use external-signing mode, which is only 1 step. See below for details.

<Tabs>
<Tab title="REST API">
### 3.1 - Send 1st Key Share

Send the first key share to BitGo. You can sign multiple transactions at once by passing the `signatureShares` parameter with the neccessary key shares for each additional transaction.

>Endpoint: [Create a Signature Share for the Transaction Request](/reference/v2wallettxrequestsignaturesharecreate)

```shell cURL
export WALLET="<WALLET_ID>"
export TX_REQUEST_ID="<TX_REQUEST_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export SHARE="<YOUR_SIGNATURE_SHARE>"
export USER_PUBLIC_GPG_KEY="<YOUR_PUBLIC_GPG_KEY>"

curl -X POST \
  https://app.bitgo-test.com/api/v2/wallet/$WALLET_ID/txrequests/$TX_REQUEST_ID/signatureshares \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "signatureShares": [
      {
        "from": "user",
        "to": "bitgo",
        "share": "'"$SHARE"'"
      }
    ],
    "userPublicGpgKey": "'"$USER_PUBLIC_GPG_KEY"'"
  }'
```

#### Step Result

```json JSON
{
  "from": "user",
  "to": "user",
  "share": "string"
}
```

### 3.2 - Get 2nd Key Share

Get the 2nd key share from BitGo.

>Endpoint: [Get Transaction Requests by Wallet](/reference/v2wallettxrequestget)

```shell cURL
export WALLET="<WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X GET \
  https://app.bitgo-test.com/api/v2/wallet/$WALLET_ID/txrequests \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

#### Step Result

```json JSON
{
  "txRequests": [
    {
      "txRequestId": "string",
      "version": 0,
      "latest": true,
      "walletId": "string",
      "walletType": "cold",
      "enterpriseId": "string",
      "state": "initialized",
      "date": "2018-05-05T19:46:22.019Z",
      "userId": "string",
      "intent": {
        "nonce": "string",
        "memo": "string",
        "intentType": "claim",
        "sequenceId": "abc123",
        "comment": "string",
        "stakingRequestId": "string",
        "stakingAddress": "string",
        "amount": {
          "value": "100",
          "symbol": "usdc"
        }
      },
      "pendingApprovalId": "string",
      "unsignedTxs": [
        {
          "serializedTxHex": "string",
          "signableHex": "string",
          "derivationPath": "string",
          "feeInfo": {
            "feeString": "string",
            "fee": 0
          }
        }
      ],
      "signatureShares": [
        {
          "from": "user",
          "to": "user",
          "share": "string"
        }
      ],
      "txHashes": [
        "string"
      ]
    }
  ],
  "nextBatchPrevId": "string"
}
```

### 3.3 - Send Complete Key Share

Send the complete key share to BitGo.

>Endpoint: [Create a Signature Share for the Transaction Request](/reference/v2wallettxrequestsignaturesharecreate)

```shell cURL
export WALLET="<WALLET_ID>"
export TX_REQUEST_ID="<TX_REQUEST_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export SHARE="<YOUR_SIGNATURE_SHARE>"
export SIGNATURE_SHARE="<BITGO_OFFSET_SECRET_SHARE>"
export USER_PUBLIC_GPG_KEY="<YOUR_PUBLIC_GPG_KEY>" # Required for ECDSA assets, such as ETH and MATIC

curl -X POST \
  https://app.bitgo-test.com/api/v2/wallet/$WALLET_ID/txrequests/$TX_REQUEST_ID/signatureshares \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "signatureShares": [
      {
        "from": "user",
        "to": "bitgo",
        "share": "'"$SHARE"'"
      }
    ],
    "signerShare": "'"$SIGNATURE_SHARE"'",
    "userPublicGpgKey": "'"$USER_PUBLIC_GPG_KEY"'"
  }'
```

#### Step Result

BitGo receives the complete key share and the transaction becomes half-signed, awaiting final signature from BitGo using the BitGo key.

```json JSON
{
  "from": "user",
  "to": "bitgo",
  "share": "string"
}
```
</Tab>
<Tab title="Express (external-signing mode)">
If you prefer to maintain your keys, in the clear, on a separate Express server, you can you can sign transactions for MPC wallets using external-signing mode. BitGo doesn't decrypt your private MPC key shares.

>Endpoint: [Sign MPC transaction](/reference/expresswalletsigntxtss)

```shell cURL
export COIN="<ASSET_ID>"
export WALLET="<WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export TX_REQUEST_ID="<TX_REQUEST_ID>"
export PRV="<YOUR_PRIVATE_KEY>"

curl -X POST \
  https://app.bitgo-test.com/api/v2/$COIN/wallet/$WALLET_ID/signtxtss \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
  "txRequestId": "'"$TX_REQUEST_ID"'",
  "prv": "'"$PRV"'"
}'
```

#### Step Result

```json JSON
{
  "txRequestId": "string",
  "version": 0,
  "latest": true,
  "walletId": "string",
  "walletType": "cold",
  "enterpriseId": "string",
  "state": "initialized",
  "date": {},
  "createdDate": {},
  "userId": "string",
  "intent": {
    "intentType": "stake",
    "sequenceId": "abc123",
    "comment": "string",
    "nonce": "string",
    "stakingRequestId": "string",
    "poolKeyHash": "string"
  },
  "intents": [
    {
      "intentType": "stake",
      "sequenceId": "abc123",
      "comment": "string",
      "nonce": "string",
      "stakingRequestId": "string",
      "poolKeyHash": "string"
    }
  ],
  "pendingApprovalId": "string",
  "isCanceled": true,
  "transactions": [
    {
      "state": "initialized",
      "unsignedTx": {
        "serializedTxHex": "string",
        "signableHex": "string",
        "derivationPath": "string",
        "feeInfo": {
          "feeString": "string",
          "fee": 0
        },
        "coinSpecific": {},
        "parsedTx": {
          "minerFee": "string",
          "spendAmount": "string",
          "spendAmounts": [
            {
              "coinName": "string",
              "amountString": "string"
            }
          ],
          "payGoFee": "string",
          "outputs": [
            {
              "address": "string",
              "isPayGo": true,
              "value": 0,
              "wallet": "string",
              "walletV1": "string",
              "baseAddress": "string",
              "enterprise": "string",
              "valueString": "string",
              "data": "string",
              "change": true,
              "coinName": "string"
            }
          ],
          "inputs": [
            {
              "derivationIndex": 0,
              "value": 0,
              "address": "string",
              "valueString": "string",
              "chain": 0,
              "index": 0
            }
          ],
          "type": "string",
          "memo": "string"
        }
      },
      "signatureShares": [
        {
          "from": "string",
          "to": "string",
          "share": "string"
        }
      ],
      "commitmentShares": [
        {
          "from": "string",
          "to": "string",
          "share": "string",
          "type": "commitment"
        }
      ],
      "txHash": "string",
      "bitgoPaillierChallenge": {
        "p": [
          "string"
        ]
      }
    }
  ],
  "messages": [
    {
      "coin": "string",
      "combineSigShare": "string",
      "createdDate": "2019-08-24T14:15:22Z",
      "messageEncoded": "string",
      "messageRaw": "string",
      "signatureShares": [
        {
          "from": "string",
          "to": "string",
          "share": "string"
        }
      ],
      "state": "initialized",
      "txHash": "string",
      "updatedDate": "2019-08-24T14:15:22Z"
    }
  ]
}
```
</Tab>
</Tabs>

## 4. Approve Consolidation

> 📘 **Note:** You can't approve your own transactions - another admin must approve them.

### 4.1 Get Pending-Approval ID

To update a pending approval, you must get the pending-approval ID for the pending approval you want to respond to.

>Endpoint: [List Pending Approvals](/reference/v2approvallist)

```shell cURL
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X GET \
  https://app.bitgo-test.com/api/v2/pendingApprovals \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

#### Step Result

```json JSON
{
  "pendingApprovals": [
    {
      "id": "59cd72485007a239fb00282ed480da1f",
      "coin": "btc",
      "wallet": "59cd72485007a239fb00282ed480da1f",
      "enterprise": "59cd72485007a239fb00282ed480da1f",
      "organization": "59cd72485007a239fb00282ed480da1f",
      "creator": "59cd72485007a239fb00282ed480da1f",
      "createDate": "2019-08-24T14:15:22Z",
      "info": {
        "transactionRequest": {
          "buildParams": {},
          "coinSpecific": {},
          "comment": "string",
          "fee": "2000000",
          "isUnsigned": true,
          "recipients": [
            {
              "address": "2MvrwRYBAuRtPTiZ5MyKg42Ke55W3fZJfZS",
              "amount": "2000000",
              "data": "string"
            }
          ],
          "requestedAmount": "2000000",
          "sourceWallet": "59cd72485007a239fb00282ed480da1f",
          "triggeredPolicy": "59cd72485007a239fb00282ed480da1f",
          "validTransaction": "string",
          "validTransactionHash": "string"
        },
        "type": "transactionRequest"
      },
      "state": "pending",
      "scope": "enterprise",
      "userIds": [
        "59cd72485007a239fb00282ed480da1f"
      ],
      "approvalsRequired": 1,
      "walletLabel": "string",
      "resolvers": [
        {
          "user": "string",
          "date": "string",
          "resolutionType": "approved",
          "signatures": [
            "string"
          ],
          "videoApprover": "string",
          "videoLink": "string",
          "videoException": "string"
        }
      ],
      "addressLabels": [
        {
          "address": "2MvrwRYBAuRtPTiZ5MyKg42Ke55W3fZJfZS",
          "label": "Bob's Hot Wallet Address",
          "walletLabel": "My Wallet"
        }
      ]
    }
  ]
}
```

### 4.2 Approve Pending Approval

>Endpoint: [Update Pending Approval](/reference/v2approvalupdate)

```shell cURL
export APPROVAL_ID="<APPROVAL_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export OTP="<YOUR_OTP>"

curl -X PUT \
  https://app.bitgo-test.com/api/v2/pendingApprovals/$APPROVAL_ID \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "state": "approved",
    "otp": "'"$OTP"'"
  }'
```
```js JavaScript
const baseCoin = this.bitgoSDK.coin(initialPendingApproval.coin);
const pendingApproval = await baseCoin.pendingApprovals().get({ id: initialPendingApproval.id });
const result = await pendingApproval.approve(params);
```

#### Step Result

Once approved, BitGo rebuilds the half-signed transaction, applying the most up-to-date fees.

```json JSON
{
    "id": "65529448bd87efe59c3b0156ddfce867",
    "coin": "tbtc4",
    "wallet": "654ec786c07fe8dc0dcfe03916ec5bb0",
    "enterprise": "62c5ae8174ac860007aff138a2d74df7",
    "creator": "62ab90e06dfda30007974f0a52a12995",
    "createDate": "2023-11-13T21:25:28.022Z",
    "info": {
        "type": "transactionRequest",
        "transactionRequest": {
            "requestedAmount": "10000",
            "fee": 20451,
            "sourceWallet": "654ec786c07fe8dc0dcfe03916ec5bb0",
            "policyUniqueId": "654ec786c07fe8dc0dcfe03f",
            "recipients": [
                {
                    "address": "2N1UvKhtSHLUa9YomSH7n9YMFCkMG2pbmsQ",
                    "amount": "10000",
                    "_id": "65529448bd87efe59c3b0158"
                }
            ],
            "coinSpecific": {
                "tbtc4": {
                    "txHex": "010000000001010e4d3af014f9efe311062965d561b67f78a1759e7016605cd506ddd7041762d50000000023220020510ded26d712922bbb61bc68ef6766f836a03527820cbdc8b1551914eb467dafffffffff02102700000000000017a9145a581567fd2a630e61e34a696ab3bb887972886d87ad0f010000000000225120850d0ab466d15cb1565dd528d4d9709f3e46f41d41fe6d94aa01378e626983990500483045022100db45a8d94ee2144f7e29baa855d94a2bf0120707a7ab2fc93734ed94af972c460220558d00b91275aafc7805dfaaf9ab796adbe9f4e66dc467f7eb93b790671a323201000069522103c10ac628c880629ed0fd2a0563a898f4882baca45e15668a4d3064cf1ea379882103e56f84be4460080618ef869bb7b07096880760f748ba23efab533c2359f923bd21020ae81372264b5eac5c9dc7fe0b9a32bad00771c3a2c71f6e2c971823c3182ed653ae00000000"
                }
            },
            "validTransaction": "010000000001010e4d3af014f9efe311062965d561b67f78a1759e7016605cd506ddd7041762d50000000023220020510ded26d712922bbb61bc68ef6766f836a03527820cbdc8b1551914eb467dafffffffff02102700000000000017a9145a581567fd2a630e61e34a696ab3bb887972886d87ad0f010000000000225120850d0ab466d15cb1565dd528d4d9709f3e46f41d41fe6d94aa01378e626983990400483045022100db45a8d94ee2144f7e29baa855d94a2bf0120707a7ab2fc93734ed94af972c460220558d00b91275aafc7805dfaaf9ab796adbe9f4e66dc467f7eb93b790671a323201473044022049e20c0073f42c9636408efc6c833ebf0e1a8ef13e8cb818dde2f4e2af7f7b7f022000cb3a321d65605b9d51d7f87e34306169607646c8d54a44011b021eff3dbe500169522103c10ac628c880629ed0fd2a0563a898f4882baca45e15668a4d3064cf1ea379882103e56f84be4460080618ef869bb7b07096880760f748ba23efab533c2359f923bd21020ae81372264b5eac5c9dc7fe0b9a32bad00771c3a2c71f6e2c971823c3182ed653ae00000000",
            "validTransactionHash": "5ea8d2b93997ed9fa3597a2f3113817c8216f573a0278c2533bb5db50fdb0dff"
        }
    },
    "state": "approved",
    "scope": "wallet",
    "userIds": [
        "62ab90e06dfda30007974f0a52a12995",
        "621d08a634ad8a0007fcddffd7c429cc"
    ],
    "approvalsRequired": 1,
    "singleRunResults": [
        {
            "ruleId": "Custody Enterprise Transaction ID Verification",
            "triggered": false,
            "_id": "65529448bd87efe59c3b0157"
        }
    ],
    "resolvers": [
        {
            "user": "621d08a634ad8a0007fcddffd7c429cc",
            "date": "2023-11-13T21:44:27.794Z",
            "resolutionType": "pending"
        }
    ]
}
```

## 5. Send Consolidation

Using the `txHex` returned in the prior step, send the half-signed transaction to BitGo.

>Endpoint: [Send Half-Signed Transaction](/reference/v2wallettxsend)

```shell cURL
export COIN="<ASSET_ID>"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/v2/$COIN/wallet/$WALLET_ID/tx/send \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "halfSigned": {
    "txHex": "010000000001010e4d3af014f9efe311062965d561b67f78a1759e7016605cd506ddd7041762d50000000023220020510ded26d712922bbb61bc68ef6766f836a03527820cbdc8b1551914eb467dafffffffff02102700000000000017a9145a581567fd2a630e61e34a696ab3bb887972886d87ad0f010000000000225120850d0ab466d15cb1565dd528d4d9709f3e46f41d41fe6d94aa01378e626983990500483045022100db45a8d94ee2144f7e29baa855d94a2bf0120707a7ab2fc93734ed94af972c460220558d00b91275aafc7805dfaaf9ab796adbe9f4e66dc467f7eb93b790671a323201000069522103c10ac628c880629ed0fd2a0563a898f4882baca45e15668a4d3064cf1ea379882103e56f84be4460080618ef869bb7b07096880760f748ba23efab533c2359f923bd21020ae81372264b5eac5c9dc7fe0b9a32bad00771c3a2c71f6e2c971823c3182ed653ae00000000"
  }
}'
```
```js JavaScript
let params = {
  txHex:
    '010000000001010e4d3af014f9efe311062965d561b67f78a1759e7016605cd506ddd7041762d50000000023220020510ded26d712922bbb61bc68ef6766f836a03527820cbdc8b1551914eb467dafffffffff02102700000000000017a9145a581567fd2a630e61e34a696ab3bb887972886d87ad0f010000000000225120850d0ab466d15cb1565dd528d4d9709f3e46f41d41fe6d94aa01378e626983990500483045022100db45a8d94ee2144f7e29baa855d94a2bf0120707a7ab2fc93734ed94af972c460220558d00b91275aafc7805dfaaf9ab796adbe9f4e66dc467f7eb93b790671a323201000069522103c10ac628c880629ed0fd2a0563a898f4882baca45e15668a4d3064cf1ea379882103e56f84be4460080618ef869bb7b07096880760f748ba23efab533c2359f923bd21020ae81372264b5eac5c9dc7fe0b9a32bad00771c3a2c71f6e2c971823c3182ed653ae00000000',
  otp: '0000000',
};
wallet.submitTransaction(params).then(function (transaction) {
  // print transaction status
  console.dir(transaction);
});
```

#### Step Result

BitGo applies the final signature using the BitGo key and broadcasts the transaction to the blockchain. Your base address receives all available assets from the receive address, maximizing your spendable balance.

```json JSON
{
  "transfer": {
    "entries": [
      {
        "address": "2NAVwU9KtPyE4h3RyHkhbLgQQvrc4EuSXD3", // sender address
        "wallet": "654ec786c07fe8dc0dcfe03916ec5bb0",
        "value": -100000,
        "valueString": "-100000"
      },
      {
        "address": "2Mw241n14gJx2PcK2kijidZ2BPGeJBdwp1A", // receiver address
        "value": 10000,
        "valueString": "10000",
        "isChange": false,
        "isPayGo": false
      },
      {
        "address": "tb1pq9m0lqjg4lfa0rj9wzjjjumk3l6vecndt8wla5756ktre6h6fexqg7z0vq", // change address that collects the UTXO
        "wallet": "654ec786c07fe8dc0dcfe03916ec5bb0",
        "value": 70013,
        "valueString": "70013",
        "isChange": true,
        "isPayGo": false
      }
    ],
    "id": "65528cde229f765c57a8f4d1eb762908",
    "coin": "tbtc4",
    "wallet": "654ec786c07fe8dc0dcfe03916ec5bb0",
    "walletType": "hot",
    "enterprise": "62c5ae8174ac860007aff138a2d74df7",
    "txid": "c68916ddc1672ec62c474ef0839ec479ad9b2dabc2249177ce6be6247f81dfe7",
    "txidType": "transactionHash",
    "height": 999999999,
    "heightId": "999999999-65528cde229f765c57a8f4d1eb762908",
    "date": "2023-11-13T20:53:51.445Z",
    "type": "send",
    "value": -29987,
    "valueString": "-29987",
    "intendedValueString": "-29987",
    "baseValue": -10000,
    "baseValueString": "-10000",
    "baseValueWithoutFees": -10000,
    "baseValueWithoutFeesString": "-10000",
    "feeString": "19987",
    "payGoFee": 0,
    "payGoFeeString": "0",
    "usd": -11.0275843085,
    "usdRate": 36774.55,
    "state": "signed",
    "instant": false,
    "isReward": false,
    "isFee": false,
    "tags": [
      "654ec786c07fe8dc0dcfe03916ec5bb0",
      "62c5ae8174ac860007aff138a2d74df7"
    ],
    "history": [
      { "date": "2023-11-13T20:53:51.444Z", "action": "signed" },
      {
        "date": "2023-11-13T20:53:50.646Z",
        "user": "62ab90e06dfda30007974f0a52a12995",
        "action": "created"
      }
    ],
    "signedDate": "2023-11-13T20:53:51.444Z",
    "vSize": 225,
    "metadata": [],
    "signedTime": "2023-11-13T20:53:51.444Z",
    "createdTime": "2023-11-13T20:53:50.646Z"
  },
  "txid": "c68916ddc1672ec62c474ef0839ec479ad9b2dabc2249177ce6be6247f81dfe7",
  "tx": "01000000000101c76ddd01e185e12e995c6f4f36bd440867296d3f224751d73432d465be93478100000000232200204fe0358ee98bef039832fa3a4dc96cb4b265448f3d89c4a05a997a3481f3da6effffffff02102700000000000017a9142962c500562c9db56434702a629ff08fcbd5add0877d110100000000002251200176ff8248afd3d78e4570a52973768ff4cce26d59ddfed3d4d5963ceafa4e4c0400483045022100c4db3db14398d5cc4c9a2a3e4a8fa4fa3b8960ad80eb840e51e182f7561cf6c102207a6410e68aaf7327a1daed83838a39b96e37e22783d879a838640035b6059bcc0147304402205888b2863bb8fc296ed51374db2d03c7fdc746fd0d6c5ceebbe2246bb76b67840220730c8b8395285767ef1049c40cd6cbdecfb5ecfefd795ac2053b28b7a6b0790f0169522103a4c6a0aa167ef75fcf4a96c53b2dd20aee3afa19d1bc2ec4354328ae87c0976621022e4d77a9d0fecafc7ad4f9cfd9144082cf146b27de945ba26d22f26438c5784b2103ee2fef2c21d48bbd0d3813c71269fca6e1bff51e676b1f0131aa29afceb08f8853ae00000000",
  "status": "signed"
}
```
</Tab>
</Tabs>

## Next

You can confirm the increased spendable balance for the wallet in BitGo or using the [Get Wallet by Coin and ID](/reference/v2walletget) endpoint. You can also view the consolidation transaction on a blockchain explorer.

## See Also

* [API Reference: Consolidate Account (Manual)](/reference/v2walletconsolidateaccountbuild)
* [API Reference: Consolidate Account (Simple)](/reference/expresswalletconsolidateaccount)
* [API Reference: Create a Signature Share for the Transaction Request](/reference/v2wallettxrequestsignaturesharecreate)
* [API Reference: Get Transaction Requests by Wallet](/reference/v2wallettxrequestget)
* [API Reference: Get Wallet by ID](/reference/v2walletgetbyid)
* [API Reference: List Pending Approvals](/reference/v2approvallist)
* [API Reference: Send Half-Signed Transaction](/reference/v2wallettxsend)
* [API Reference: Sign MPC Transaction](/reference/expresswalletsigntxtss)
* [API Reference: Update Pending Approval](/reference/v2approvalupdate)
* [Concept: Consolidations](/docs/consolidations)
