sendTransaction

Sends a transaction using the provided account.

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 {
sendTransaction,
getContract,
prepareContractCall,
} from "thirdweb";
import { sepolia } from "thirdweb/chains";
const contract = getContract({
address: "0x...",
chain: sepolia,
client,
});
const transaction = prepareContractCall({
contract,
method: "function transfer(address to, uint256 value)",
params: [to, value],
});
const { transactionHash } = await sendTransaction({
account,
transaction,
});

Using a write extension

import { sendTransaction, getContract } from "thirdweb";
import { sepolia } from "thirdweb/chains";
import { mintTo } from "thirdweb/extensions/erc721";
const contract = getContract({
address: "0x...",
chain: sepolia,
client,
});
const transaction = mintTo({
contract,
to: "0x...",
nft: {
name: "NFT Name",
description: "NFT Description",
image: "https://example.com/image.png",
},
});
const { transactionHash } = await sendTransaction({
account,
transaction,
});

Using a prepared transaction

import {
sendTransaction,
getContract,
prepareTransaction,
} from "thirdweb";
import { sepolia } from "thirdweb/chains";
const contract = getContract({
address: "0x...",
chain: sepolia,
client,
});
const transaction = prepareTransaction({
contract,
to: "0x...",
value: toWei("0.1"),
});
const { transactionHash } = await sendTransaction({
account,
transaction,
});

Parameters

Returns

A promise that resolves to the transaction result.