Skip to content

Latest commit

 

History

History
82 lines (60 loc) · 2.54 KB

File metadata and controls

82 lines (60 loc) · 2.54 KB
description sidebar_position
Learn how to create a delegator account using Viem.
2

import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem";

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 },
});
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:

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