# Deposit and withdraw

### Deposit and encumber funds

At the commitment time, the price and the seller's deposit get locked in the protocol. The buyer's funds are transferred to the protocol alongside the commitment action, while the seller's funds should already be available in the protocol. The seller's funds can already be in the protocol as a result of previous exchanges. If there are none (since no exchange was finalised yet), the seller can deposit them into the protocol and make them available for future exchanges.

Only the seller needs the depositing functionality, and it's not allowed to deposit funds for entities of a different type.

### Release and withdraw funds

When the exchange is finalised, all exchange funds are released to the recipients, depending on the final exchange state. The recipients can then withdraw them from the protocol. They can combine payouts of multiple exchanges and withdraw them all at once. Sellers can leave the funds to be used as a seller deposit for future exchanges.

The pull mechanics are used instead of push, since otherwise the malicious actors could block the finalisation of the exchange.

***

### TypeScript SDK

{% tabs %}
{% tab title="Deposit funds" %}
Transfers the ERC20 tokens or native token to the protocol and makes it available to be used as a seller's deposit.

<pre class="language-typescript"><code class="lang-typescript"><strong>const sellerId = "2";
</strong><strong>const amount = parseEther("0.01");
</strong><strong>const tokenAddress = "0x00000000000000000000000000000000"; // native token
</strong><strong>
</strong>await coreSDK.depositFunds(sellerId, amount, tokenAddress);
</code></pre>

{% endtab %}

{% tab title="Withdraw funds" %}
Transfers ERC20 tokens or native tokens from the protocol to the entity's address.

#### Withdraw specific tokens and amount

```typescript
const entityId = "6";
const tokenList = [
    "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
    "0x0000000000000000000000000000000000000000"
    ];
const tokenAmounts = [parseEther("0.03"), parseEther("0.05")];

await coreSdk.withdrawFunds(entityId, tokenList, tokenAmounts);
```

#### Withdraw all available funds

```typescript
const entityId = "6";

await coreSdk.withdrawAllAvailableFunds(entityId);
```

{% endtab %}
{% endtabs %}

### Solidity

{% tabs %}
{% tab title="Deposit funds" %}
Transfers the ERC20 tokens or native token to the protocol and makes it available to be used as a seller's deposit.

```solidity
IBosonFundsHandler bosonProtocol = IBosonFundsHandler(_bosonProtocolAddress);
uint256 sellerId = 2;
uint256 amount = 0.01 ether;
address tokenAddress = 0x00000000000000000000000000000000; // native token

bosonProtocol.depositFunds{ value: amount }(seller, tokenAddress, amount);
```

{% endtab %}

{% tab title="Withdraw funds" %}
Transfers ERC20 tokens or native tokens from the protocol to the entity's address.

#### Withdraw specific tokens and amount

```solidity
IBosonFundsHandler bosonProtocol = IBosonFundsHandler(_bosonProtocolAddress);
uint256 entityId = 6;
address[] memory tokenList = new address[](2);
uint256[] memory tokenAmounts = new uint256[](2);

tokenList[0] = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
tokenList[1] = 0x0000000000000000000000000000000000000000;

tokenAmounts[0] = 0.03 ether;
tokenAmounts[1] = 0.05 ether;

bosonProtocol.withdrawFunds(entityId, tokenList, tokenAmounts);
```

#### Withdraw all available funds

```solidity
IBosonFundsHandler bosonProtocol = IBosonFundsHandler(_bosonProtocolAddress);
uint256 entityId = 6;
// Empty lists mean "all"
address[] memory tokenList;
uint256[] memory tokenAmounts;

bosonProtocol.withdrawFunds(entityId, tokenList, tokenAmounts);
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bosonprotocol.io/v2.4.2/using-the-protocol/dacp-tools/finances/deposit-and-withdraw.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
