> For the complete documentation index, see [llms.txt](/llms.txt).

# EIP-7702 quickstart

This quickstart demonstrates how to upgrade your [EOA](/smart-accounts-kit/development/reference/glossary#externally-owned-account-eoa)**Externally owned account (EOA)** A private-key-controlled account with no built-in programmable execution logic. to support [MetaMask smart account](/smart-accounts-kit/development/reference/glossary#metamask-smart-account)**MetaMask smart account** A smart contract account created using the Smart Accounts Kit that supports programmable behavior, flexible signing options, and ERC-7710 delegations.functionality using an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) transaction. This enables your EOA to leverage the benefits of [account abstraction](/smart-accounts-kit/development/reference/glossary#account-abstraction)**Account abstraction** A conceptual model for programmable onchain accounts, including flexible validation logic, custom signature schemes, and gas abstraction. ERC-4337 defines a mechanism for account abstraction., such as batch transactions, gas sponsorship, and [delegation](/smart-accounts-kit/development/reference/glossary#delegation)**Delegation** The ability for a MetaMask smart account to authorize another account to perform specific executions on its behalf..

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
- Install [Yarn](https://yarnpkg.com/), [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.
- [Install Viem](https://viem.sh/).

## Steps[​](#steps "Direct link to Steps")

### 1. Install the Smart Accounts Kit[​](#1-install-the-smart-accounts-kit "Direct link to 1. Install the Smart Accounts Kit")

Install the [Smart Accounts Kit](https://www.npmjs.com/package/@metamask/smart-accounts-kit):

- npm
- Yarn
- pnpm
- Bun

```
npm install @metamask/smart-accounts-kit

```

```
yarn add @metamask/smart-accounts-kit

```

```
pnpm add @metamask/smart-accounts-kit

```

```
bun add @metamask/smart-accounts-kit

```

### 2. Set up a Public Client[​](#2-set-up-a-public-client "Direct link to 2. Set up a Public Client")

Set up a Public Client using Viem's [createPublicClient](https://viem.sh/docs/clients/public) function. This client will let the EOA query the account state and interact with the blockchain network.

```
import { createPublicClient, http } from 'viem'
import { sepolia as chain } from 'viem/chains'

const publicClient = createPublicClient({
  chain,
  transport: http(),
})

```

### 3. Set up a Bundler Client[​](#3-set-up-a-bundler-client "Direct link to 3. Set up a Bundler Client")

Set up a Bundler Client using Viem's [createBundlerClient](https://viem.sh/account-abstraction/clients/bundler) function. This lets you use the [bundler](/smart-accounts-kit/development/reference/glossary#bundler)**Bundler** An ERC-4337 component that manages the alternate mempool: it collects user operations from smart accounts, packages them, and submits them to the network. service to estimate gas for [user operations](/smart-accounts-kit/development/reference/glossary#user-operation)**User operation** A pseudo-transaction object defined by ERC-4337 that describes what a smart account should execute. User operations are submitted to the alternate mempool managed by bundlers. and submit transactions to the network.

```
import { createBundlerClient } from 'viem/account-abstraction'

const bundlerClient = createBundlerClient({
  client: publicClient,
  transport: http('https://your-bundler-rpc.com'),
})

```

### 4. Set up a Wallet Client[​](#4-set-up-a-wallet-client "Direct link to 4. Set up a Wallet Client")

Set up a Wallet Client using Viem's [createWalletClient](https://viem.sh/docs/clients/wallet) function. This lets you sign and submit [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) authorizations.

```
import { createWalletClient, http } from 'viem'
import { sepolia as chain } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'

export const account = privateKeyToAccount('0x...')

export const walletClient = createWalletClient({
  account,
  chain,
  transport: http(),
})

```

### 5. Authorize a 7702 delegation[​](#5-authorize-a-7702-delegation "Direct link to 5. Authorize a 7702 delegation")

Create an authorization to map the contract code to an [EOA](/smart-accounts-kit/development/reference/glossary#externally-owned-account-eoa)**Externally owned account (EOA)** A private-key-controlled account with no built-in programmable execution logic., and sign it using Viem's [signAuthorization](https://viem.sh/docs/eip7702/signAuthorization) action. The `signAuthorization` action does not support JSON-RPC accounts.

This example uses [EIP7702StatelessDeleGator](https://github.com/MetaMask/delegation-framework/blob/main/src/EIP7702/EIP7702StatelessDeleGator.sol) as the [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) delegator contract. It follows a stateless design, as it does not store signer data in the contract's state. This approach provides a lightweight and secure way to upgrade an EOA to a [MetaMask smart account](/smart-accounts-kit/development/reference/glossary#metamask-smart-account)**MetaMask smart account** A smart contract account created using the Smart Accounts Kit that supports programmable behavior, flexible signing options, and ERC-7710 delegations..

```
import {
  Implementation,
  toMetaMaskSmartAccount,
  getSmartAccountsEnvironment,
} from '@metamask/smart-accounts-kit'
import { privateKeyToAccount } from 'viem/accounts'

const environment = getSmartAccountsEnvironment(sepolia.id)
const contractAddress = environment.implementations.EIP7702StatelessDeleGatorImpl

const authorization = await walletClient.signAuthorization({
  account,
  contractAddress,
  executor: 'self',
})

```

### 6. Submit the authorization[​](#6-submit-the-authorization "Direct link to 6. Submit the authorization")

Once you have signed an authorization, you can send an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) transaction to set the EOA code. Since the authorization cannot be sent by itself, you can include it alongside a dummy transaction.

```
import { zeroAddress } from 'viem'

const hash = await walletClient.sendTransaction({
  authorizationList: [authorization],
  data: '0x',
  to: zeroAddress,
})

```

### 7. Create a MetaMask smart account[​](#7-create-a-metamask-smart-account "Direct link to 7. Create a MetaMask smart account")

Create a [smart account](/smart-accounts-kit/development/reference/glossary#metamask-smart-account)**MetaMask smart account** A smart contract account created using the Smart Accounts Kit that supports programmable behavior, flexible signing options, and ERC-7710 delegations. instance for the EOA and start leveraging the benefits of [account abstraction](/smart-accounts-kit/development/reference/glossary#account-abstraction)**Account abstraction** A conceptual model for programmable onchain accounts, including flexible validation logic, custom signature schemes, and gas abstraction. ERC-4337 defines a mechanism for account abstraction..

```
import { Implementation, toMetaMaskSmartAccount } from '@metamask/smart-accounts-kit'

const addresses = await walletClient.getAddresses()
const address = addresses[0]

const smartAccount = await toMetaMaskSmartAccount({
  client: publicClient,
  implementation: Implementation.Stateless7702,
  address,
  signer: { walletClient },
})

```

### 8. Send a user operation[​](#8-send-a-user-operation "Direct link to 8. Send a user operation")

Send a [user operation](/smart-accounts-kit/development/reference/glossary#user-operation)**User operation** A pseudo-transaction object defined by ERC-4337 that describes what a smart account should execute. User operations are submitted to the alternate mempool managed by bundlers. through the upgraded EOA, using Viem's [sendUserOperation](https://viem.sh/account-abstraction/actions/bundler/sendUserOperation) method.

```
import { parseEther } from 'viem'

// Appropriate fee per gas must be determined for the specific bundler being used.
const maxFeePerGas = 1n
const maxPriorityFeePerGas = 1n

const userOperationHash = await bundlerClient.sendUserOperation({
  account: smartAccount,
  calls: [
    {
      to: '0x1234567890123456789012345678901234567890',
      value: parseEther('1'),
    },
  ],
  maxFeePerGas,
  maxPriorityFeePerGas,
})

```

## Next steps[​](#next-steps "Direct link to Next steps")

- To grant specific permissions to other accounts from your smart account, [create a delegation](/smart-accounts-kit/development/guides/delegation/execute-on-smart-accounts-behalf/).
- To quickly bootstrap a MetaMask Smart Accounts project, [use the CLI](/smart-accounts-kit/development/get-started/use-the-cli/).
- You can also [use MetaMask Connect to upgrade a MetaMask account to a smart account](/tutorials/upgrade-eoa-to-smart-account/).
