sendTransactionSync
Creates, signs, and sends a new transaction to the network, and waits for the transaction to be included in a block. Returns the transaction receipt.
Usage
import { , } from './config'
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n
})Account Hoisting
If you do not wish to pass an account to every sendTransaction, you can also hoist the Account on the Wallet Client (see config.ts).
import { } from './config'
const = await .sendTransactionSync({
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n
})Returns
The Transaction hash.
Parameters
account
- Type:
Account | Address | null
The Account to send the transaction from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc). If set to null, it is assumed that the transport will handle filling the sender of the transaction.
const = await .sendTransactionSync({
: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n
})to
- Type:
0x${string}
The transaction recipient or contract address.
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n,
: 69
})accessList (optional)
- Type:
AccessList
The access list.
const = await .sendTransactionSync({
: [
{
: '0x1',
: ['0x1'],
},
],
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})authorizationList (optional)
- Type:
AuthorizationList
Signed EIP-7702 Authorization list.
const = await .signAuthorization({
,
: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
const = await .sendTransactionSync({
,
: [],
: '0xdeadbeef',
: .address,
})blobs (optional)
- Type:
Hex[]
Blobs for Blob Transactions.
import * as cKzg from 'c-kzg'
import { toBlobs, setupKzg, stringToHex } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'
const kzg = setupKzg(cKzg, mainnetTrustedSetupPath)
const receipt = await walletClient.sendTransactionSync({
account,
blobs: toBlobs({ data: stringToHex('blobby blob!') }),
kzg,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8'
})chain (optional)
- Type:
Chain - Default:
walletClient.chain
The target chain. If there is a mismatch between the wallet's current chain & the target chain, an error will be thrown.
The chain is also used to infer its request type (e.g. the Celo chain has a gatewayFee that you can pass through to sendTransactionSync).
import { } from 'viem/chains'
const = await .sendTransactionSync({
: ,
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n
})data (optional)
- Type:
0x${string}
A contract hashed method call with encoded args.
const = await .sendTransactionSync({
: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n
})gas (optional)
- Type:
bigint
The gas limit of the transaction. If missing, it will be estimated.
const = await .sendTransactionSync({
,
: 21000n,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: parseEther('1')
})gasPrice (optional)
- Type:
bigint
The price (in wei) to pay per gas. Only applies to Legacy Transactions.
const = await .sendTransactionSync({
,
: parseGwei('20'),
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: parseEther('1')
})kzg (optional)
- Type:
KZG
KZG implementation for Blob Transactions.
See setupKzg for more information.
import * as cKzg from 'c-kzg'
import { toBlobs, setupKzg, stringToHex } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'
const kzg = setupKzg(cKzg, mainnetTrustedSetupPath)
const receipt = await walletClient.sendTransactionSync({
account,
blobs: toBlobs({ data: stringToHex('blobby blob!') }),
kzg,
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8'
})maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions
const = await .sendTransactionSync({
,
: parseGwei('20'),
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: parseEther('1')
})maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions
const = await .sendTransactionSync({
,
: parseGwei('20'),
: parseGwei('2'),
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: parseEther('1')
})nonce (optional)
- Type:
number
Unique number identifying this transaction.
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n,
: 69
})pollingInterval (optional)
- Type:
number - Default:
walletClient.pollingInterval
The polling interval to poll for the transaction receipt.
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n,
: 69,
: 1_000
})throwOnReceiptRevert (optional)
- Type:
boolean
Whether to throw an error if the transaction was detected as reverted.
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n,
: 69,
: true
})timeout (optional)
- Type:
number - Default:
chain.blockTime * 3
The timeout to wait for the transaction receipt.
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: 1000000000000000000n,
: 69,
: 20_000
})value (optional)
- Type:
bigint
Value in wei sent with this transaction.
const = await .sendTransactionSync({
,
: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
: parseEther('1'),
: 69
})Tips
- For dapps: When using this action, it is assumed that the user has connected to their wallet (e.g. given permission for the dapp to access their accounts via
requestAddresses). You can also check if the user has granted access to their accounts viagetAddresses
JSON-RPC Methods
- JSON-RPC Accounts:
- Local Accounts:
eth_sendRawTransactionSync