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.
- example.ts
- config.ts
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 },
});
import { http, createPublicClient } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { lineaSepolia as chain } from "viem/chains";
const transport = http();
export const publicClient = createPublicClient({
transport,
chain,
});
const privateKey = generatePrivateKey();
export const owner = privateKeyToAccount(privateKey);
This example creates the MetaMaskSmartAccount
, which can perform several functions:
- In conjunction with Viem Account Abstraction clients, deploy the smart account and send user operations.
- Sign delegations that can be used to grant specific rights and permissions to other accounts. Smart accounts that sign delegations are called delegator accounts.
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.