> For the complete documentation index, see [llms.txt](https://docs.cometh.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cometh.io/integrations/react-hooks/usesendtransaction.md).

# useSendTransaction

## Description

This hook provides functionality to send either a single transaction or multiple transactions in batch. It uses the smart account client to process and send these transactions.

It supports both synchronous and asynchronous methods for sending transactions, making it versatile for various use cases.

## Returns

* **data** (`Hash | undefined`): The hash of the transaction if it was successfully sent, otherwise `undefined`.
* **error** (`Error | null`): An error object if the transaction failed, otherwise `null`.
* **isPending** (`boolean`): A boolean indicating whether the transaction is currently pending.
* **isSuccess** (`boolean`): A boolean indicating whether the transaction was successfully sent.
* **isError** (`boolean`): A boolean indicating whether an error occurred during the transaction process.
* **sendTransaction** (`SendTransactionMutate`): A function that sends the transaction(s) without waiting for a result.&#x20;
* **sendTransactionAsync** (`SendTransactionMutateAsync`): A function that sends the transaction(s) and returns a promise that resolves to the transaction hash.

## Example

```tsx
import { useSendTransaction } from "@cometh/connect-react-hooks";
import { useState } from "react";
import { parseEther, Address } from "viem";
 
export const TransactionSender = () => {
  const { sendTransaction, sendTransactionAsync, isLoading, isError, error, isSuccess, data } = useSendTransaction();
  const [recipient, setRecipient] = useState<Address>();
  const [amount, setAmount] = useState<string>("0");
 
  const handleSendTransaction = () => {
    if (recipient) {
      sendTransaction({
       calls: {
          to: recipient,
          value: parseEther(amount),
          data: "0x",
        }
      });
    }
  };
 
  const handleSendBatchTransactions = async () => {
    if (recipient) {
      try {
       const hash = await sendTransactionAsync({
         calls: [
           {
              to: recipient,
              value: parseEther(amount),
              data: "0x",
           },
           {
             to: recipient,
             value: parseEther((Number(amount) * 2).toString()),
             data: "0x",
           }
          ]
        });
        console.log("Batch transactions sent! Hash:", hash);
      } catch (error) {
        console.error("Error sending batch transactions:", error);
      }
    }
  };
 
  return (
    <div>
      <input
        placeholder="Recipient address"
        onChange={(e) => setRecipient(e.target.value as Address)}
      />
      <input
        type="number"
        placeholder="Amount in ETH"
        onChange={(e) => setAmount(e.target.value)}
      />
      <button onClick={handleSendTransaction} disabled={isLoading}>
        Send Transaction
      </button>
      <button onClick={handleSendBatchTransactions} disabled={isLoading}>
        Send Batch Transactions
      </button>
      {isError && <p>Error: {error.message}</p>}
      {isSuccess && <p>Transaction sent! Hash: {data}</p>}
    </div>
  );
};
```


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.cometh.io/integrations/react-hooks/usesendtransaction.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
