> **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.

# `SmartAccount.from`

The `SmartAccount.from` function allows you to create a Smart Account with a custom account implementation.

## Import

```ts twoslash
import { SmartAccount } from 'viem/erc4337'
```

## Usage

To instantiate a Smart Account, you will need to provide an account implementation.

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

const account = await SmartAccount.from({
  client,
  entryPoint: {
    abi: [/* ... */],
    address: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
    version: '0.7',
  },

  async decodeCalls(_data) {
    // Decode calls from the account's execution calldata.
    return []
  },
  async encodeCalls(_calls) {
    // Encode calls for the account contract.
    return '0x' as const
  },
  async getAddress() {
    // Resolve the Smart Account address.
    return '0x0000000000000000000000000000000000000000' as const
  },
  async getFactoryArgs() {
    // Build the factory properties used to deploy the account.
    return {
      factory: '0xda4b37208c41c4f6d1b101cac61e182fe1da0754',
      factoryData: '0x',
    } as const
  },
  async getNonce() {
    // Get the Smart Account nonce.
    return 0n
  },
  async getStubSignature() {
    // Return a stub signature for gas estimation.
    return '0x' as const
  },
  async signMessage() {
    // Sign a message for verification by the account contract.
    return '0x' as const
  },
  async signTypedData() {
    // Sign typed data for verification by the account contract.
    return '0x' as const
  },
  async signUserOperation() {
    // Sign a User Operation for submission to a Bundler.
    return '0x' as const
  },

  // Optionally extend the account with custom properties.
  extend: {
    abi: [/* ... */],
    factory: {
      abi: [/* ... */],
      address: '0xda4b37208c41c4f6d1b101cac61e182fe1da0754',
    },
  },
  // Optionally customize User Operation preparation.
  userOperation: {
    async estimateGas() {
      return undefined
    },
  },
})
```

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

export const client = Client.create({
  chain: mainnet,
  transport: http(),
})
```
:::

## Returns

`SmartAccount.SmartAccount`

The Smart Account.

## Parameters

### authorization

* **Type:** `{ account: Account.PrivateKey, address: Address }`

EIP-7702 delegation used to deploy the account.

### client

* **Type:** `Client`

Client used to read account and EntryPoint state.

### decodeCalls

* **Type:** `(data: Hex) => readonly Call[] | Promise<readonly Call[]>`

Decodes account execution calldata into calls.

### encodeCalls

* **Type:** `(calls: readonly Call[]) => Hex | Promise<Hex>`

Encodes calls as account execution calldata.

### entryPoint

* **Type:** `{ abi: Abi, address: Address, version: '0.6' | '0.7' | '0.8' | '0.9' }`

EntryPoint supported by the account.

### extend

* **Type:** `object`

Additional properties exposed by the returned account.

### getAddress

* **Type:** `() => Address | Promise<Address>`

Returns the account address.

### getFactoryArgs

* **Type:** `() => FactoryArgs | Promise<FactoryArgs>`

Returns the factory address and calldata for an undeployed account.

### getNonce

* **Type:** `(options?: { key?: bigint }) => bigint | Promise<bigint>`

Overrides the default EntryPoint nonce lookup.

### getStubSignature

* **Type:** `(userOperation?) => Hex | Promise<Hex>`

Returns a placeholder signature for gas estimation.

### nonceKeyManager

* **Type:** `NonceManager`

Manages automatically allocated EntryPoint nonce keys.

### sign

* **Type:** `(options: { hash: Hex }) => Hex | Promise<Hex>`

Signs a raw hash and enables the returned account's `sign` method.

### signMessage

* **Type:** `Account.Local['signMessage']`

Signs an EIP-191 personal message with the owner.

### signTypedData

* **Type:** `Account.Local['signTypedData']`

Signs EIP-712 typed data with the owner.

### signUserOperation

* **Type:** `(userOperation) => Hex | Promise<Hex>`

Signs a User Operation with the owner.

### userOperation

* **Type:** `{ estimateGas? }`

Account-specific User Operation preparation hooks.
