# Withdrawal

## Withdrawal

Withdrawal will move assets from DeFi Account `address` to target address. If withdrawal has source in Virtual Account, liabilities balance is first moved from Virtual Account to DeFi Account,  and then assets are moved on-chain.

### Estimate fees

You can estimate blockchain transaction fee.

{% tabs %}
{% tab title="First Tab" %}

```shell
echo 'calculate blockchain fees'

curl --location --request GET 'https://api.orangepill.cloud/v1/withdrawals/estimate \
--header 'x-api-key: AXVubzpwQDU1dzByYM==' \
--header 'Content-Type: application/json' \
--data-raw '{
    "account": "634b56217f6a7b0be52dffca",
    "address": "bc1qxyvqcwepfwsxstemz626uc73n0w6nxh3swgh68",
    "amount": 0.15,
    "speed": "fast"
}'
```

{% endtab %}
{% endtabs %}

In response you will get fee values for `slow`, `medium` or `fast` processing speed.

```json
"0.000684"
```

### Create Withdrawal

Withdrawal will create on-chain transaction from `account` to `address`.

Blockchain fee can be charged to sender or receiver. If it is charged to sender, fee is added to transaction value. If it is charged to receiver, fee is deducted from transaction value.

{% tabs %}
{% tab title="cURL" %}

```shell

echo 'create withdrawal from virtual account 634b56217f6a7b0be52dffca to Bitcoin address bc1qxyvqcwepfwsxstemz626uc73n0w6nxh3swgh68'

curl --location --request POST 'https://api.orangepill.cloud/v1/withdrawals \
--header 'x-api-key: AXVubzpwQDU1dzByYM==' \
--header 'idempotency-key: 27373fabc392933deffff' \
--header 'Content-Type: application/json' \
--data-raw '{
    "source": {
        "account": "634b56217f6a7b0be52dffca"
    },
    "destination": {
        "address": "bc1qxyvqcwepfwsxstemz626uc73n0w6nxh3swgh68"
    },
    "asset": "BTC",
    "value": 0.15,
    "fee": {
        "paid_by": "receiver",
        "speed": "fast"
    },
    "data": {
        "my_field_1": "Salary 11/2022",
        "my_field_2": "I1234",        
    }
}'

```

{% endtab %}
{% endtabs %}

In response you will get processing withdrawal.

```json
{
    "id": "634b56217f6a7b0be52dffac",
    "source": {
        "account": "634b56217f6a7b0be52dffca",
        "ramp": "637176640b45bd060bdced17",
        "address": "637176640b45bd060bdced17"
    },
    "destination": {
        "address": "bc1qxyvqcwepfwsxstemz626uc73n0w6nxh3swgh68"
    },
    "asset": "BTC",
    "value": 0.15,
    "fee": {
        "paid_by": "receiver",
        "speed": "fast",
        "value": 0.0005
    },
    "data": {
        "my_field_1": "Salary 11/2022",
        "my_field_2": "I1234",        
    },
    "amount": 0.1495,
    "status": "PROCESSING",
    "created_at": "1519211809934",
    "error": null
}
```
