• Core
  • Actions
  • sendTransaction

sendTransaction

Action for sending a transaction.

This is a wrapper around viem's sendTransaction.

import { sendTransaction } from '@wagmi/core'

Usage

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

Prepared Usage

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

Return Value

{
  hash: `0x${string}`
}

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 { hash } = await sendTransaction({
  chainId: 1,
  to: 'jxom.eth',
  value: parseEther('1'),
})

account (optional)

The Account to send the transaction from.

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

gasPrice (optional)

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

const { hash } = await sendTransaction({
  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 { hash } = await sendTransaction({
  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 { hash } = await sendTransaction({
  to: 'jxom.eth',
  value: parseEther('1'),
  maxPriorityFeePerGas: parseGwei('20'),
})

nonce (optional)

Unique number identifying this transaction.

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

value (optional)

Value in wei sent with this transaction.

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