> 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/escrow-react-sdk/usesendtransaction.md).

# useSendTransaction

Most Trustless Work endpoints return an unsigned transaction in XDR format. This endpoint is used to sign such unsigned transactions and send them to the Stellar network.

{% hint style="info" %}
This endpoint must be used for all the endpoints after we execute it. Except getEscrowBalances, getEscrowsByContractId, getEscrowsByRole and getEscrowsBySigner .
{% endhint %}

## Usage

This custom hook exposes a function to send a signed transaction to the network.&#x20;

{% code overflow="wrap" %}

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

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

/* 
 * It returns a SendTransactionResponse
 * payload should be of type string
*/
const data = await sendTransaction(signedXdr);

```

{% endcode %}

### Function

* `sendTransaction`\
  Responsible for building and returning data based on the provided payload.

*Argument:*

`payload`: An string containing the required fields to send a transaction to the network.

{% content-ref url="/pages/mCiAw7wa82TjvbS32nkX" %}
[Types](/trustless-work/introduction/developer-resources/types.md)
{% endcontent-ref %}

*Return Value:*

**For:** Fund Escrow, Resolve Dispute, Change Milestone Status, Change Milestone Approved Flag, Start Dispute, Release Funds:

* This object will be a type of *sendTransactionResponse*.&#x20;

**For:** Initialize Escrow:

* This object will be a type of *sendTransactionResponse*. But you can set it as *InitializeEscrowResponse*.

**For:** Update Escrow:

* This object will be a type of *sendTransactionResponse*. But you can set it as *UpdateEscrowResponse*.

***

## Usage Example

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

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

export const useSomeEndpointForm= () => {

 /*
  *  useSomeEndpoint
 */
 const { someFunction } = useSomeEndpoint();
 
 /*
  *  useSendTransaction
 */
 const { sendTransaction } = useSendTransaction();

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

    try {
      // get unsignedTransaction from some endpoint ...

      /**
       * @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);

    } catch (error: unknown) {
      // catch error logic
    }
  };
}

```

{% 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.trustlesswork.com/trustless-work/escrow-react-sdk/usesendtransaction.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
