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,
});

Gasless usage with thirdweb Engine

const { transactionHash } = await sendTransaction({
account,
transaction,
gasless: {
provider: "engine",
relayerUrl:
"https://thirdweb.engine-***.thirdweb.com/relayer/***",
relayerForwarderAddress: "0x...",
},
});

Gasless usage with OpenZeppelin

const { transactionHash } = await sendTransaction({
account,
transaction,
gasless: {
provider: "openzeppelin",
relayerUrl: "https://...",
relayerForwarderAddress: "0x...",
},
});
function sendTransaction(

Parameters

The options for sending the transaction.

Type

let options: {
account: Account;
gasless: GaslessOptions;
transaction: PreparedTransaction<any>;
};

Returns

let returnType: Prettify<
SendTransactionResult & {
chain: Chain;
client: ThirdwebClient;
maxBlocksWaitTime?: number;
}
>;

A promise that resolves to the transaction result.