• Core
  • Actions
  • prepareSendTransaction

prepareSendTransaction

Action for preparing a transaction to be sent via sendTransaction.

Eagerly fetches the parameters required for sending a transaction such as the gas estimate and resolving an ENS address (if required).

import { prepareSendTransaction } from '@wagmi/core'

Usage

prepareSendTransaction gives back a "prepared request" to be sent through to sendTransaction.

import { prepareSendTransaction, sendTransaction } from '@wagmi/core'
 
const request = await prepareSendTransaction({
  to: 'moxey.eth',
  value: parseEther('1'),
})
const { hash } = await sendTransaction(request)

Return value

{
  accessList?: AccessList,
  account?: Account,
  chainId?: number,
  data?: Hex,
  gas?: bigint,
  gasPrice?: bigint,
  maxFeePerGas?: bigint,
  maxPriorityFeePerGas?: bigint,
  mode: 'prepared',
  nonce?: number,
  to: string,
  value?: bigint,
}

Configuration

chainId (optional)

Checks the current chain to make sure it is the same as chainId. If chainId is not the current chain, the Action will throw an error.

const request = await prepareSendTransaction({
  chainId: 1,
  to: 'jxom.eth',
  value: parseEther('1'),
})

account (optional)

The Account to send the transaction from.

const request = await prepareSendTransaction({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  to: 'jxom.eth',
  value: parseEther('1'),
})

gasPrice (optional)

The price (in wei) to pay per gas. Only applies to Legacy Transactions.

const request = await prepareSendTransaction({
  to: 'jxom.eth',
  value: parseEther('1'),
  gasPrice: parseGwei('20'),
})

maxFeePerGas (optional)

Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions

const request = await prepareSendTransaction({
  to: 'jxom.eth',
  value: parseEther('1'),
  maxFeePerGas: parseGwei('20'),
})

maxPriorityFeePerGas (optional)

Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions

const request = await prepareSendTransaction({
  to: 'jxom.eth',
  value: parseEther('1'),
  maxPriorityFeePerGas: parseGwei('20'),
})

nonce (optional)

Unique number identifying this transaction.

const request = await prepareSendTransaction({
  to: 'jxom.eth',
  value: parseEther('1'),
  nonce: 69,
})

value (optional)

Value in wei sent with this transaction.

const request = await prepareSendTransaction({
  to: 'jxom.eth',
  value: parseEther('1'),
})