> For the complete documentation index, see [llms.txt](https://docs.trustlesswork.com/trustless-work/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trustlesswork.com/trustless-work/v1-pt/sdk-react-de-escrow/indexador/usegetescrowsfromindexerbyrole.md).

# useGetEscrowsFromIndexerByRole

## Uso

Este hook customizado expõe uma função para obter os depósitos em garantia que você está procurando.

{% code overflow="wrap" %}

```typescript
import { useGetEscrowsFromIndexerByRole } from "@trustless-work/escrow/hooks";
import { GetEscrowsFromIndexerByRoleParams } from "@trustless-work/escrow/types";

/*
 *  useGetEscrowsFromIndexerByRole 
*/
const { getEscrowsByRole } = useGetEscrowsFromIndexerByRole();

/* 
 * Retorna os depósitos em garantia que você está procurando
 * o payload deve ser do tipo `GetEscrowsFromIndexerByRoleParams`
*/
await getEscrowsByRole(payload);
```

{% endcode %}

### Função

* `getEscrowsByRole`\
  Responsável por construir e retornar dados com base no payload fornecido.

*Argumento:*

`GetEscrowsFromIndexerByRoleParams`: Um objeto contendo os campos necessários para obter os depósitos em garantia por função.

{% content-ref url="/pages/d3e5f1329189a4637cf79e2933fb57d371fe4acb" %}
[Obter escrows por função](/trustless-work/v1-pt/introducao/developer-resources/tipos/payloads/obter-escrows-por-funcao.md)
{% endcontent-ref %}

*Valor de Retorno:*

`escrows`: Os depósitos em garantia que você está procurando.

***

## Exemplo de UsoForm

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

```typescript
import {
  useGetEscrowsFromIndexerByRole,
} from "@trustless-work/escrow/hooks";
import {
  GetEscrowsFromIndexerByRoleParams, 
} from "@trustless-work/escrow/types";

export const useGetEscrowsFromIndexerByRoleForm = () => {

 /*
  *  useGetEscrowsFromIndexerByRole
 */
 const { getEscrowsByRole } = useGetEscrowsFromIndexerByRole();

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

    try {
      /**
       * Chamada de API usando os hooks do trustless work
       * @Note:
       * - Precisamos passar o payload para a função getEscrowsByRole
       * - O resultado será um depósito em garantia
      */
      const escrows = await getEscrowsByRole(payload);
      
      if (!escrows) {
        throw new Error("Escrows not found");
      }

      /**
       * @Responses:
       * escrows !== null
       * - Depósitos em garantia recebidos com sucesso
       * - Mostrar um toast de sucesso
       *
       * escrows === null
       * - Mostrar um toast de erro
       */
      if (escrows) {
        toast.success("Escrows Received");
      }
    } catch (error: unknown) {
      // lógica para capturar erro
    }
  };
}

```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/indexador/usegetescrowsfromindexerbyrole.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.
