Skip to content

sendRawTransaction

Action for sending a signed transaction to the network.

Import

ts
import { sendRawTransaction } from '@wagmi/core'

Usage

ts
import { sendRawTransaction, signTransaction } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'

const serializedTransaction = await signTransaction(config, {
  to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  value: parseEther('0.01'),
})

const result = await sendRawTransaction(config, {
  serializedTransaction
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type SendRawTransactionParameters } from '@wagmi/core'

chainId

config['chains'][number]['id'] | undefined

Chain ID to validate against before sending transaction.

ts
import { sendRawTransaction, signTransaction } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { parseEther } from 'viem'
import { config } from './config'

const serializedTransaction = await signTransaction(config, {
  chainId: mainnet.id,
  to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  value: parseEther('0.01'),
})

const result = await sendRawTransaction(config, {
  chainId: mainnet.id, 
  serializedTransaction
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

connector

Connector | undefined

  • Connector to send the raw transaction with.
  • Defaults to current connector.
ts
import { getConnections, sendRawTransaction, signTransaction } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'

const connections = getConnections(config)

const serializedTransaction = await signTransaction(config, {
  connector: connections[0]?.connector,
  to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  value: parseEther('0.01'),
})

const result = await sendRawTransaction(config, {
  connector: connections[0]?.connector, 
  serializedTransaction
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

serializedTransaction

`0x${string}`

The signed serialized transaction.

ts
import { sendRawTransaction, signTransaction } from '@wagmi/core'
import { parseEther } from 'viem'
import { config } from './config'

const serializedTransaction = await signTransaction(config, {
  to: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  value: parseEther('0.01'),
})

const result = await sendRawTransaction(config, {
  serializedTransaction
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Return Type

ts
import { type SendRawTransactionReturnType } from '@wagmi/core'

Hash

Transaction hash.

Error

ts
import { type SendRawTransactionErrorType } from '@wagmi/core'

TanStack Query

ts
import {
  type SendRawTransactionData,
  type SendRawTransactionVariables,
  type SendRawTransactionMutate,
  type SendRawTransactionMutateAsync,
  sendRawTransactionMutationOptions,
} from '@wagmi/core/query'

Viem

Released under the MIT License.