# Deallocate Assets

Source: https://developers.bitgo.com/docs/oes-client-deallocate

## Overview

Deallocate assets from a connected partner to your Go Network account. Deallocating assets unlocks them at BitGo, making them available for any other action, such as rebalancing or withdrawing. Deallocations occur synchronously. You can view your deallocated balance from the BitGo web application or programmatically.

## Prerequisites

* [Get Started](/docs/get-started-intro)
* [Connect to Partners](/docs/oes-client-connect)
* [Allocate Assets](/docs/oes-client-allocate)

## Cookbook

Need just the steps? Expand the cookbook below to get started:

<Cookbook slug="oes-client-deallocate" title="Deallocate Assets" />

## 1. Get Deallocation Payload

>Endpoint: [Get Signing Payload for Client Deallocations](/reference/v1clientdeallocationssigninggetroute)

```shell cURL
export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"
export CONNECTION_ID="<YOUR_CONNECTION_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/network/v1/enterprises/$ENTERPRISE_ID/clients/connections/$CONNECTION_ID/deallocations/signing \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "amount": {
      "currency": "string",
      "quantity": "string"
    },
    "clientExternalId": "string",
    "nonce": "string",
    "notes": "string"
  }'
```

#### Step Result

```json JSON
{
  "payload": "string"
}
```

## 2. Create Deallocation Request

>Endpoint: [Deallocate Funds to Partner Connection](/reference/v1clientdeallocationspostroute)

```shell cURL
export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"
export CONNECTION_ID="<YOUR_CONNECTION_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/network/v1/enterprises/$ENTERPRISE_ID/clients/connections/$CONNECTION_ID/deallocations \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "amount": {
      "currency": "string",
      "quantity": "string"
    },
    "clientExternalId": "string",
    "payload": "string", # The payload string received in the previous step
    "signature": "string",
    "nonce": "string",
    "notes": "string"
  }'
```
```js JavaScript
import { BitGoAPI } from '@bitgo/sdk-api';
import { v4 as uuidV4 } from 'uuid';
import crypto from 'crypto';
import { TradingAccount } from '@bitgo/sdk-core/dist/src/bitgo/trading/trading';
import * as dotenv from 'dotenv';

// --- Required Constants ---
const accessToken = process.env.ACCESS_TOKEN;
const walletId = process.env.WALLET_ID;
const enterpriseId = process.env.ENTERPRISE_ID;
const walletPassphrase = process.env.WALLET_PASSPHRASE;
const connectionId = process.env.CONNECTION_ID;

const bitgo = new BitGoAPI({
  accessToken: accessToken,
  env: 'test',
  customRootURI: 'https://app.bitgo-test.com',
});

const coin = 'ofc';
bitgo.register(coin, coins.Ofc.createInstance);

async function createDeallocation() {
  try {
    // 1. Get the wallet and instantiate the trading account
    console.log(`Fetching wallet: ${walletId}...`);
    const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
    const tradingAccount = new TradingAccount(enterpriseId, wallet, bitgo);
    const network = tradingAccount.toNetwork();

    // 2. Prepare the deallocation, which creates the payload and signature
    console.log('Preparing deallocation...');
    const deallocationParams = await network.prepareDeallocation({
      walletPassphrase,
      connectionId,
      amount: {
        currency: 'ofctbtc',
        quantity: '50000',
      },
      notes: 'Deallocation for Project Phoenix',
    });

    // 3. Create the deallocation using the prepared parameters.
    console.log('Creating deallocation...');
    const deallocation = await network.createDeallocation(deallocationParams);

    console.log('Deallocation created successfully:');
    console.dir(deallocation, { depth: null });

  } catch (error) {
    console.error('Failed to create deallocation:', error);
  }
}

createDeallocation();
```

#### Step Result

```json JSON
{
  "deallocation": {
    "status": "cleared",
    "retriable": false,
    "id": "string",
    "amount": {
      "currency": "string",
      "quantity": "string"
    },
    "connectionId": "string",
    "clientExternalId": "string",
    "partnerExternalId": "string",
    "initiatedBy": "string",
    "notes": "string",
    "createdAt": "2019-08-24T00:00:00.000Z",
    "updatedAt": "2019-08-24T00:00:00.000Z"
  }
}
```

## Next

[View Go Network Details](/docs/oes-client-view-details)

## See Also

[API Reference: Deallocate Funds from Connection](/reference/v1clientdeallocationspostroute)
