# useWithdrawRemainingFunds

## Uso

Este hook personalizado expõe uma função para sacar os fundos restantes em um 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();

/* 
 * Retorna uma transação não assinada
<strong> * payload deve ser do tipo `WithdrawRemainingFundsPayload`
</strong>*/
const { unsignedTransaction } = await withdrawRemainingFunds(payload);

</code></pre>

### Função de Mutação

`withdrawRemainingFunds`

Responsável por construir e retornar uma transação não assinada com base no payload fornecido.

**TipoDeEscrow**: Especifica o tipo de escrow. Aceita os seguintes valores:

* **multi-release**: Permite múltiplos desembolsos de fundos.

**WithdrawRemainingFundsPayload:** Um objeto com campos necessários para liberar os fundos bloqueados

**Parâmetros**:

Permite apenas escrows de liberação múltipla..

* **payload**: Um objeto contendo os campos obrigatórios para resolver uma disputa.

{% content-ref url="/pages/83ce1ced5233d0b08575488d0872c35ffba8dcd7" %}
[Sacar fundos restantes](/trustless-work/v1-pt/introducao/developer-resources/tipos/payloads/sacar-fundos-restantes.md)
{% endcontent-ref %}

*Valor de Retorno:*

`unsignedTransaction`: Um objeto representando a transação construída, pronto para ser assinado pela sua carteira e transmitido.

***

## Exemplo de Uso

{% 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();

/*
 * função onSubmit, isso pode ser chamada por um botão de formulário
*/
 const onSubmit = async (payload: WithdrawRemainingFundsPayload) => {

    try {
      /**
       * Chamada de API usando os hooks do trustless work
       * @Nota:
       * - Precisamos passar o payload para a função withdrawRemainingFunds
       * - O resultado será uma transação não assinada
       */
      const { unsignedTransaction } = await withdrawRemainingFunds (
        payload
      );

      if (!unsignedTransaction) {
        throw new Error(
          "Transação não assinada está faltando em withdrawRemainingFunds."
        );
      }

      /**
       * @Nota:
       * - Precisamos assinar a transação usando sua [chave privada], como uma carteira
       * - O resultado será uma transação assinada
       */
      const signedXdr = await signTransaction({ /* Este método deve ser fornecido pela carteira */
        unsignedTransaction,
        address: walletAddress || "",
      });

      if (!signedXdr) {
        throw new Error("Transação assinada está ausente.");
      }

      /**
       * @Nota:
       * - Precisamos enviar a transação assinada para a API
       * - Os dados serão um SendTransactionResponse
       */
      const data = await sendTransaction(signedXdr);

      /**
       * @Respostas:
       * data.status === "SUCCESS"
       * - Disputa resolvida com sucesso
       * - Mostrar um toast de sucesso
       *
       * data.status == "ERROR"
       * - Mostrar um toast de erro
       */
      if (data.status === "SUCCESS") {
         toast.success("Retirada bem-sucedida");
      }
    } catch (error: unknown) {
      // lógica de captura de erro
    }
  };
}

```

{% 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/v1-pt/sdk-react-de-escrow/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.
