# UserOperation.from

Instantiates a [`UserOperation.UserOperation`](/ercs/erc4337/UserOperation/types#useroperation) from a provided input.

## Imports

:::code-group
```ts [Named]
import { UserOperation } from 'ox/erc4337'
```

```ts [Entrypoint]
import * as UserOperation from 'ox/erc4337/UserOperation'
```
:::

## Examples

```ts twoslash
import { Value } from 'ox'
import { UserOperation } from 'ox/erc4337'

const userOperation = UserOperation.from({
  callData: '0xdeadbeef',
  callGasLimit: 300_000n,
  maxFeePerGas: Value.fromGwei('20'),
  maxPriorityFeePerGas: Value.fromGwei('2'),
  nonce: 69n,
  preVerificationGas: 100_000n,
  sender: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
  verificationGasLimit: 100_000n
})
```

### From Packed User Operation

```ts twoslash
import { UserOperation } from 'ox/erc4337'

const packed: UserOperation.Packed = {
  accountGasLimits: '0x...',
  callData: '0xdeadbeef',
  initCode: '0x',
  gasFees: '0x...',
  nonce: 69n,
  paymasterAndData: '0x',
  preVerificationGas: 100_000n,
  sender: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
  signature: '0x'
}

const userOperation = UserOperation.from(packed)
```

### Attaching Signatures

```ts twoslash
import { Secp256k1, Value } from 'ox'
import { UserOperation } from 'ox/erc4337'

const userOperation = UserOperation.from({
  callData: '0xdeadbeef',
  callGasLimit: 300_000n,
  maxFeePerGas: Value.fromGwei('20'),
  maxPriorityFeePerGas: Value.fromGwei('2'),
  nonce: 69n,
  preVerificationGas: 100_000n,
  sender: '0x9f1fdab6458c5fc642fa0f4c5af7473c46837357',
  verificationGasLimit: 100_000n
})

const payload = UserOperation.getSignPayload(
  userOperation,
  {
    chainId: 1,
    entryPointAddress:
      '0x1234567890123456789012345678901234567890',
    entryPointVersion: '0.7'
  }
)

const signature = Secp256k1.sign({
  payload,
  privateKey: '0x...'
})

const userOperation_signed = UserOperation.from(
  userOperation,
  { signature }
) // [!code focus]
```

## Definition

```ts
function from<userOperation, signature>(
  userOperation: userOperation | UserOperation | Packed,
  options?: from.Options<signature>,
): from.ReturnType<userOperation, signature>
```

**Source:** [src/erc4337/UserOperation.ts](https://github.com/wevm/ox/blob/main/src/erc4337/UserOperation.ts#L1098)

## Parameters

### userOperation

* **Type:** `userOperation | UserOperation | Packed`

The user operation to instantiate (structured or packed format).

### options

* **Type:** `from.Options<signature>`
* **Optional**

#### options.signature

* **Type:** `0x${string} | { r: 0x${string}; s: 0x${string}; yParity: number; } | signature`
* **Optional**

## Return Type

User Operation.

`from.ReturnType<userOperation, signature>`
