# useWithdrawRemainingFunds

## Usage

This custom hook exposes a function to do the withdraw remaining funds in an escrow.

<pre class="language-typescript" data-overflow="wrap"><code class="lang-typescript">import { useResolveDispute } from "@trustless-work/escrow/hooks";
import { WithdrawRemainingFundsPayload } from "@trustless-work/escrow/types";

/*
 *  useWithdrawRemainingFunds
*/
const { withdrawRemainingFunds} = useWithdrawRemainingFunds();

/* 
 * It returns an unsigned transaction
<strong> * payload should be of type `WithdrawRemainingFundsPayload`
</strong>*/
const { unsignedTransaction } = await withdrawRemainingFunds(payload);

</code></pre>

### Mutation Function

`withdrawRemainingFunds`

Responsible for building and returning an unsigned transaction based on the provided payload.

**EscrowType**: Specifies the type of escrow. It accepts the following values:

* **multi-release**: Allows for multiple releases of funds.

**WithdrawRemainingFundsPayload:** An object with fields necessary to release the locked funds

**Parameters**:

Only allows multi-release escrows..

* **payload**: An object containing the required fields to resolve a dispute.

{% content-ref url="/pages/v8FzrsfBEHYrCMQVMsUD" %}
[Withdraw Remaining Funds](/trustless-work/v2-en/introduction/developer-resources/types/payloads/withdraw-remaining-funds.md)
{% endcontent-ref %}

*Return Value:*

`unsignedTransaction`: An object representing the constructed transaction, ready to be signed by your wallet and broadcast.

***

## Usage Example

{% code title="src/hooks/useWithdrawRemainingFundsForm.ts" overflow="wrap" %}

```typescript
import {
  useWithdrawRemainingFunds,
  useSendTransaction,
} from "@trustless-work/escrow/hooks";
import {
  WithdrawRemainingFundsPayload
} from "@trustless-work/escrow/types";

export const useStartDisputeForm = () => {

 /*
  *  useWithdrawRemainingFunds
 */
 const { withdrawRemainingFunds } = useWithdrawRemainingFunds();
 
 /*
  *  useSendTransaction
 */
 const { sendTransaction } = useSendTransaction();

/*
 * onSubmit function, this could be called by form button
*/
 const onSubmit = async (payload: WithdrawRemainingFundsPayload) => {

    try {
      /**
       * API call by using the trustless work hooks
       * @Note:
       * - We need to pass the payload to the withdrawRemainingFunds function
       * - The result will be an unsigned transaction
       */
      const { unsignedTransaction } = await withdrawRemainingFunds (
        payload
      );

      if (!unsignedTransaction) {
        throw new Error(
          "Unsigned transaction is missing from withdrawRemainingFunds."
        );
      }

      /**
       * @Note:
       * - We need to sign the transaction using your [private key] such as wallet
       * - The result will be a signed transaction
       */
      const signedXdr = await signTransaction({ /* This method should be provided by the wallet */
        unsignedTransaction,
        address: walletAddress || "",
      });

      if (!signedXdr) {
        throw new Error("Signed transaction is missing.");
      }

      /**
       * @Note:
       * - We need to send the signed transaction to the API
       * - The data will be an SendTransactionResponse
       */
      const data = await sendTransaction(signedXdr);

      /**
       * @Responses:
       * data.status === "SUCCESS"
       * - Dispute resolved successfully
       * - Show a success toast
       *
       * data.status == "ERROR"
       * - Show an error toast
       */
      if (data.status === "SUCCESS") {
         toast.success("Withdrawal successful");
      }
    } catch (error: unknown) {
      // catch error logic
    }
  };
}

```

{% endcode %}


---

# 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.trustlesswork.com/trustless-work/v2-en/escrow-react-sdk/escrows/usewithdrawremainingfunds.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.
