useSendTransaction

A hook to send a transaction with from the user's connected wallet.

You can send a transaction with a prepared contract call , a prepared transaction , or using a write Extension .

Example

Using a prepared contract call

import { useSendTransaction } from "thirdweb/react";
import { getContract, prepareContractCall } from "thirdweb";
import { sepolia } from "thirdweb/chains";
const contract = getContract({
address: "0x...",
chain: sepolia,
client,
});
const { mutate: sendTx, data: transactionResult } = useSendTransaction();
const onClick = () => {
const transaction = prepareContractCall({
contract,
method: "function transfer(address to, uint256 value)",
params: [to, value],
}),
});
sendTx(transaction);
};

Using a write extension

import { useSendTransaction } from "thirdweb/react";
import { mintTo } from "thirdweb/extensions/erc721";
const { mutate: sendTx, data: transactionResult } =
useSendTransaction();
const onClick = () => {
const transaction = mintTo({
contract,
to: "0x...",
nft: {
name: "NFT Name",
description: "NFT Description",
image: "https://example.com/image.png",
},
});
sendTx(transaction);
};

Sending a prepared transaction

import { useSendTransaction } from "thirdweb/react";
import { getContract, prepareTransaction } from "thirdweb";
import { sepolia } from "thirdweb/chains";
const contract = getContract({
address: "0x...",
chain: sepolia,
client,
});
const { mutate: sendTx, data: transactionResult } = useSendTransaction();
const onClick = () => {
const transaction = prepareTransaction({
contract,
to: "0x...",
value: toWei("0.1"),
}),
});
sendTx(transaction);
};

Parameters

Returns

A UseMutationResult object to send a transaction.