Skip to main content

Create a smart account

The MetaMask Delegation Toolkit is embedded, meaning that the end user can instantly interact with a dapp without wallet authorization, confirmations, or corporate logos. Enable users to create a smart account directly in your dapp.

Prerequisites

Create a MetaMaskSmartAccount

The following is an example of creating a smart account using Viem Core SDK. Viem Core SDK provides low-level interfaces to offer flexibility and control over the smart account creation lifecycle.

In the example, the Viem privateKeyToAccount function creates an externally owned account as the owner of the smart account.

import { publicClient, owner } from "./config.ts";
import {
Implementation,
toMetaMaskSmartAccount,
} from "@metamask/delegation-toolkit";

const deploySalt = "0x";

const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner.address, [], [], []],
deploySalt,
signatory: { account: owner },
});

This example creates the MetaMaskSmartAccount, which can perform several functions:

note

The example above uses a Hybrid smart account, which is configurable to have an EOA "owner" and any number of P256 (passkey) signers. You can also configure other smart account types.