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

# Configure the Smart Accounts Kit

The Smart Accounts Kit is highly configurable, providing support for custom [bundlers](/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. and [paymasters](/smart-accounts-kit/development/reference/glossary#paymaster)**Paymaster** A service that pays for user operations on behalf of a smart account.. You can also configure the toolkit environment to interact with the [Delegation Framework](/smart-accounts-kit/development/reference/glossary#delegation-framework)**Delegation Framework** A set of audited smart contracts that handle smart account creation, the delegation lifecycle, and caveat enforcement..

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

[Install and set up the Smart Accounts Kit.](/smart-accounts-kit/development/get-started/install/)

## Configure the bundler[​](#configure-the-bundler "Direct link to Configure the bundler")

The toolkit uses Viem's Account Abstraction API to configure custom [bundlers](/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. and [paymasters](/smart-accounts-kit/development/reference/glossary#paymaster)**Paymaster** A service that pays for user operations on behalf of a smart account.. This provides a robust and flexible foundation for creating and managing [MetaMask Smart Accounts](/smart-accounts-kit/development/concepts/smart-accounts/). See Viem's [account abstraction documentation](https://viem.sh/account-abstraction) for more information on the API's features, methods, and best practices.

To use the bundler and paymaster clients with the toolkit, create instances of these clients and configure them as follows:

```
import { createPaymasterClient, createBundlerClient } from 'viem/account-abstraction'
import { http } from 'viem'
import { sepolia as chain } from 'viem/chains'

// Replace these URLs with your actual bundler and paymaster endpoints.
const bundlerUrl = 'https://your-bundler-url.com'
const paymasterUrl = 'https://your-paymaster-url.com'

// The paymaster is optional.
const paymasterClient = createPaymasterClient({
  transport: http(paymasterUrl),
})

const bundlerClient = createBundlerClient({
  transport: http(bundlerUrl),
  paymaster: paymasterClient,
  chain,
})

```

Replace the bundler and paymaster URLs with your bundler and paymaster endpoints. For example, you can use endpoints from [Pimlico](https://docs.pimlico.io/references/bundler), [Infura](/services/), or [ZeroDev](https://docs.zerodev.app/meta-infra/intro).

note

Providing a paymaster is optional when configuring your bundler client. However, if you choose not to use a paymaster, the smart account must have enough funds to pay gas fees.

## (Optional) Configure the toolkit environment[​](#optional-configure-the-toolkit-environment "Direct link to (Optional) Configure the toolkit environment")

The toolkit environment (`SmartAccountsEnvironment`) defines the contract addresses necessary for interacting with the [Delegation Framework](/smart-accounts-kit/development/concepts/delegation/overview/#delegation-framework) on a specific network. It serves several key purposes:

- It provides a centralized configuration for all the contract addresses required by the Delegation Framework.
- It enables easy switching between different networks (for example, Mainnet and testnet) or custom deployments.
- It ensures consistency across different parts of the application that interact with the Delegation Framework.

### Resolve the environment[​](#resolve-the-environment "Direct link to Resolve the environment")

When you create 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., the toolkit automatically resolves the environment based on the version it requires and the chain configured. If no environment is found for the specified chain, it throws an error.

- example.ts
- config.ts

```
import { SmartAccountsEnvironment } from '@metamask/smart-accounts-kit'
import { delegatorSmartAccount } from './config.ts'

const environment: SmartAccountsEnvironment = delegatorSmartAccount.environment

```

```
import {
  Implementation,
  toMetaMaskSmartAccount,
} from "@metamask/smart-accounts-kit";
import { privateKeyToAccount } from "viem/accounts";
import { createPublicClient, http } from "viem";
import { sepolia as chain } from "viem/chains";

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

const delegatorAccount = privateKeyToAccount("0x...");

const delegatorSmartAccount = await toMetaMaskSmartAccount({
  client: publicClient,
  implementation: Implementation.Hybrid,
  deployParams: [delegatorAccount.address, [], [], []],
  deploySalt: "0x",
  signer: { account: delegatorAccount },
});

export delegatorSmartAccount;

```

note

See the changelog of the toolkit version you are using (in the left sidebar) for supported chains.

Alternatively, you can use the [getSmartAccountsEnvironment](/smart-accounts-kit/development/reference/delegation/#getsmartaccountsenvironment) function to resolve the environment. This function is especially useful if your [delegator](/smart-accounts-kit/development/reference/glossary#delegator-account)**Delegator account** The account that creates and signs a delegation to grant limited authority to another account. is not a smart account when creating a [redelegation](/smart-accounts-kit/development/reference/glossary#redelegation)**Redelegation** A delegation that passes on authority granted by a previous delegation..

```
import { getSmartAccountsEnvironment, SmartAccountsEnvironment } from '@metamask/smart-accounts-kit'
import { sepolia } from 'viem/chains'

// Resolves the SmartAccountsEnvironment for Sepolia
const environment: SmartAccountsEnvironment = getSmartAccountsEnvironment(sepolia.id)

```

### Deploy a custom environment[​](#deploy-a-custom-environment "Direct link to Deploy a custom environment")

You can deploy the contracts using any method, but the toolkit provides a convenient [deploySmartAccountsEnvironment](/smart-accounts-kit/development/reference/delegation/#deploysmartaccountsenvironment) function. This function simplifies deploying the [Delegation Framework](/smart-accounts-kit/development/reference/glossary#delegation-framework)**Delegation Framework** A set of audited smart contracts that handle smart account creation, the delegation lifecycle, and caveat enforcement. contracts to your desired EVM chain.

This function requires a Viem [Public Client](https://viem.sh/docs/clients/public), [Wallet Client](https://viem.sh/docs/clients/wallet), and [Chain](https://viem.sh/docs/glossary/types#chain)to deploy the contracts and resolve the `SmartAccountsEnvironment`.

Your wallet must have a sufficient native token balance to deploy the contracts.

- example.ts
- config.ts

```
import { walletClient, publicClient } from './config.ts'
import { sepolia as chain } from 'viem/chains'
import { deploySmartAccountsEnvironment } from '@metamask/smart-accounts-kit/utils'

const environment = await deploySmartAccountsEnvironment(walletClient, publicClient, chain)

```

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

// Your deployer wallet private key.
const privateKey = '0x123..'
const account = privateKeyToAccount(privateKey)

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

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

```

You can also override specific contracts when calling `deploySmartAccountsEnvironment`. For example, if you've already deployed the `EntryPoint` contract on the target chain, you can pass the contract address to the function.

```
// The config.ts is the same as in the previous example.
import { walletClient, publicClient } from "./config.ts";
import { sepolia as chain } from "viem/chains";
import { deploySmartAccountsEnvironment } from "@metamask/smart-accounts-kit/utils";

const environment = await deploySmartAccountsEnvironment(
  walletClient,
  publicClient,
  chain,
+ {
+   EntryPoint: "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
+ }
);

```

Once the contracts are deployed, you can use them to override the environment.

### Override the environment[​](#override-the-environment "Direct link to Override the environment")

To override the environment, the toolkit provides an [overrideDeployedEnvironment](/smart-accounts-kit/development/reference/delegation/#overridedeployedenvironment) function to resolve `SmartAccountsEnvironment` with specified contracts for the given chain and contract version.

```
// The config.ts is the same as in the previous example.
import { walletClient, publicClient } from './config.ts'
import { sepolia as chain } from 'viem/chains'
import { SmartAccountsEnvironment } from '@metamask/smart-accounts-kit'
import {
  overrideDeployedEnvironment,
  deploySmartAccountsEnvironment,
} from '@metamask/smart-accounts-kit'

const environment: SmartAccountsEnvironment = await deploySmartAccountsEnvironment(
  walletClient,
  publicClient,
  chain
)

overrideDeployedEnvironment(chain.id, '1.3.0', environment)

```

If you've already deployed the contracts using a different method, you can create a `SmartAccountsEnvironment` instance with the required contract addresses, and pass it to the function.

```
- import { walletClient, publicClient } from "./config.ts";
- import { sepolia as chain } from "viem/chains";
import { SmartAccountsEnvironment } from "@metamask/smart-accounts-kit";
import {
  overrideDeployedEnvironment,
- deploySmartAccountsEnvironment
} from "@metamask/smart-accounts-kit";

- const environment: SmartAccountsEnvironment = await deploySmartAccountsEnvironment(
-  walletClient,
-  publicClient,
-  chain
- );

+ const environment: SmartAccountsEnvironment = {
+  SimpleFactory: "0x124..",
+  // ...
+  implementations: {
+    // ...
+  },
+ };

overrideDeployedEnvironment(
  chain.id,
  "1.3.0",
  environment
);

```

note

Make sure to specify the [Delegation Framework](/smart-accounts-kit/development/reference/glossary#delegation-framework)**Delegation Framework** A set of audited smart contracts that handle smart account creation, the delegation lifecycle, and caveat enforcement. version required by the toolkit. See the changelog of the toolkit version you are using (in the left sidebar) for its required Framework version.
