> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Sign Transaction \[transaction.sign]

Signs a transaction. Local Accounts sign locally (no JSON-RPC request); JSON-RPC Accounts sign via `eth_signTransaction`.

## Usage

This example signs a transaction.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const signed = await client.transaction.sign({
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
// @log: '0x02f86b0180843b9aca008502540be400825208...'
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  transport: http(),
}).extend(walletActions())
```
:::

### Standalone Action

Call `Actions.transaction.sign` directly by passing the Client as the first argument.

:::code-group
```ts twoslash [example.ts]
import { Actions } from 'viem'
import { client } from './viem.config'

const signed = await Actions.transaction.sign(client, {
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
// @log: '0x02f86b0180843b9aca008502540be400825208...'
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  transport: http(),
})
```
:::

## Recipes

### Prepare Before Signing

Set `prepare` when the request does not already contain its nonce, chain ID, gas, fee, and
transaction type fields.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const signed = await client.transaction.sign({
  prepare: true, // [!code focus]
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
// @log: '0x02f86b0180843b9aca008502540be400825208...'
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  transport: http(),
}).extend(walletActions())
```
:::

### Sign with a Connected Wallet

Use a JSON-RPC Account when a connected wallet holds the signing key. The wallet receives an
`eth_signTransaction` request.

:::code-group
```ts twoslash [example.ts]
import { client } from './viem.config'

const signed = await client.transaction.sign({
  prepare: true,
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
// @log: '0x02f86b0180843b9aca008502540be400825208...'
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Client, custom, walletActions } from 'viem'
import { mainnet } from 'viem/chains'
import 'viem/window'

export const client = Client.create({
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', // [!code focus]
  chain: mainnet,
  transport: custom(window.ethereum!),
}).extend(walletActions())
```
:::

### Sign Blob Data

Pass encoded blobs and a configured KZG adapter when signing an EIP-4844 transaction. Preparation
derives the remaining blob and transaction fields.

:::code-group
```ts twoslash [example.ts]
import { Blobs, Hex, Kzg } from 'viem/utils'
import { client } from './viem.config'

export async function signBlob(kzg: Kzg.Kzg) {
  return client.transaction.sign({
    blobs: Blobs.from(Hex.fromString('Hello from a blob')), // [!code focus]
    kzg, // [!code focus]
    prepare: true, // [!code focus]
    to: '0x0000000000000000000000000000000000000000',
  })
}
```

```ts twoslash [viem.config.ts] filename="viem.config.ts"
import { Account, Client, http, walletActions } from 'viem'
import { mainnet } from 'viem/chains'

export const client = Client.create({
  account: Account.fromPrivateKey('0x…'),
  chain: mainnet,
  transport: http(),
}).extend(walletActions())
```
:::

## Return Value

`Hex`

The signed serialized transaction.

## Parameters

### accessList

* **Type:** `AccessList`

The EIP-2930 access list to attach to the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  accessList: [ // [!code focus]
    { // [!code focus]
      address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', // [!code focus]
      storageKeys: [ // [!code focus]
        '0x0000000000000000000000000000000000000000000000000000000000000001', // [!code focus]
      ], // [!code focus]
    }, // [!code focus]
  ], // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### account

* **Type:** `Account | Address`
* **Default:** `client.account`

The Account (or address) signing the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  account: Account.fromPrivateKey('0x…'), // [!code focus]
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
```

### authorizationList

* **Type:** `AuthorizationList`

The EIP-7702 (signed) authorization list to attach to the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  authorizationList: [ // [!code focus]
    { // [!code focus]
      address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', // [!code focus]
      chainId: 1, // [!code focus]
      nonce: 0n, // [!code focus]
      r: '0x...', // [!code focus]
      s: '0x...', // [!code focus]
      yParity: 0, // [!code focus]
    }, // [!code focus]
  ], // [!code focus]
})
```

### blobs

* **Type:** `readonly Hex[]`

The blobs to attach to the transaction (EIP-4844). Use with [`kzg`](#kzg) to derive the blob fields.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { Kzg } from 'viem/utils'

const blobData = '0x1234' as const
const kzg = {} as Kzg.Kzg
const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  blobs: [blobData], // [!code focus]
  kzg, // [!code focus]
  maxFeePerBlobGas: 1_000_000_000n,
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### chain

* **Type:** `Chain | null`
* **Default:** `client.chain`

The chain the transaction targets. Asserts the chain matches the connected network before signing. Pass `null` to skip the current-chain assertion.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  chain: optimism, // [!code focus]
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
```

### data

* **Type:** `Hex`

The calldata to send with the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  data: '0x06fdde03', // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### gas

* **Type:** `bigint | number | Hex`

The gas limit for the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  gas: 21_000n, // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### gasPrice

* **Type:** `bigint | number | Hex`

The legacy gas price (in wei). Mutually exclusive with `maxFeePerGas`/`maxPriorityFeePerGas`.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  gasPrice: 20_000_000_000n, // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### kzg

* **Type:** `Kzg`

The KZG context used to derive EIP-4844 blob fields from [`blobs`](#blobs).

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'
import { Kzg } from 'viem/utils'

const blobData = '0x1234' as const
const kzg = {} as Kzg.Kzg
const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  blobs: [blobData],
  kzg, // [!code focus]
  maxFeePerBlobGas: 1_000_000_000n,
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### maxFeePerBlobGas

* **Type:** `bigint | number | Hex`

The max fee per blob gas (in wei) the sender is willing to pay (EIP-4844).

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  maxFeePerBlobGas: 1_000_000_000n, // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### maxFeePerGas

* **Type:** `bigint | number | Hex`

The total fee per gas (in wei) the sender is willing to pay (EIP-1559).

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  maxFeePerGas: 20_000_000_000n, // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### maxPriorityFeePerGas

* **Type:** `bigint | number | Hex`

The max priority fee per gas (in wei) to pay to the block producer (EIP-1559).

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  maxPriorityFeePerGas: 1_000_000_000n, // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### nonce

* **Type:** `bigint | number | Hex`

The nonce to use for the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  nonce: 69, // [!code focus]
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
```

### prepare

* **Type:** `boolean`
* **Default:** `false`

Whether to use
[`Actions.transaction.prepare`](/docs/actions/public/transaction/prepare) before signing.
Preparation populates `nonce`, `chainId`, fees, `gas`, and `type`.

When `false`, the action signs the request without preparing it.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  prepare: true, // [!code focus]
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
```

### requestOptions

* **Type:** `{ dedupe?: boolean; signal?: AbortSignal; ... }`

Per-request transport options forwarded to the JSON-RPC `eth_signTransaction` request (JSON-RPC Accounts only).

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const client = Client.create({ chain: mainnet, transport: http() })
// ---cut---
const controller = new AbortController()
const signed = await Actions.transaction.sign(client, {
  account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  requestOptions: { signal: controller.signal }, // [!code focus]
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1n,
})
```

### to

* **Type:** `Address`

The contract address or recipient of the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // [!code focus]
  value: 1n,
})
```

### type

* **Type:** `string`

Forces the transaction request to a specific type, such as `'eip1559'`, `'eip2930'`, or
`'legacy'`.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  type: 'eip1559', // [!code focus]
})
```

### value

* **Type:** `bigint | number | Hex`

The value (in wei) sent with the transaction.

```ts twoslash
import { Account, Actions, Client, http } from 'viem'
import { mainnet } from 'viem/chains'

const account = Account.fromPrivateKey('0x…')
const client = Client.create({ account, chain: mainnet, transport: http() })
// ---cut---
const signed = await Actions.transaction.sign(client, {
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1000000000000000000n, // [!code focus]
})
```

## Errors

| Error | Description |
| --- | --- |
| `Account.NotFoundError` | No Account was provided on the Action or the Client. |
| `Chain.NotFoundError` | No chain was provided and the Client has no chain. |
| `Chain.MismatchError` | The chain does not match the connected network. |
