Skip to main content

Configure smart accounts and signers

The MetaMask Delegation Toolkit supports different smart account types, each with its own configuration and support for different signing mechanisms. You can create flexible and secure delegator accounts tailored to your specific needs.

Prerequisites

Configure a Hybrid smart account

The Hybrid smart account supports both an EOA "owner" and any number of P256 (passkey) signers.

To configure a Hybrid smart account, provide the following parameters:

  • owner: The owner's account address as a hex string. The owner can be the zero address, indicating that there is no owner configured.
  • p256KeyIds: An array of key identifiers for P256 signers as hex strings.
  • p256XValues: An array of public key x-values for P256 signers as bigints.
  • p256YValues: An array of public key y-values for P256 signers as bigints.
  • signatory: A signer that will sign on behalf of the smart account.
note

You can set all p256 parameters to empty arrays to configure no WebAuthn signer. However, we recommend configuring at least one signer for account recoverability.

For a Hybrid smart account, you can configure the following types of signatories:

Configure an account signatory

This example creates a signatory from a private key using Viem's privateKeyToAccount function.

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

const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
deploySalt: "0x",
signatory,
});

Configure a Wallet Client signatory

This example creates a Viem Wallet Client as the signatory, using Viem's createWalletClient function.

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

const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
deploySalt: "0x",
signatory,
});

Configure a WebAuthn (passkey) signatory

This example creates a Viem WebAuthn Account as the signatory, using Viem's toWebAuthnAccount function.

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

const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
deploySalt: "0x",
signatory,
});

Configure a Multisig smart account

The Multisig smart account supports multiple EOA signers with a configurable threshold for execution.

To configure a Multisig smart account, provide the following parameters:

  • signers: An array of EOA signer addresses as hex strings.
  • threshold: The number of signers required to execute a transaction, as a bigint.
  • signatory: An array of signatories that will sign on behalf of the smart account.

Configure signatories

For a Multisig smart account, you can use a combination of account signatories and Wallet Client signatories. For example:

import { publicClient } from "./client.ts";
import { account, walletClient } from "./signers.ts";
import {
Implementation,
toMetaMaskSmartAccount,
} from "@metamask/delegation-toolkit";

const signers = [ account.address, walletClient.address ];
const signatory = [ { account }, { walletClient } ];
const threshold = 2n

const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.MultiSig,
deployParams: [signers, threshold],
deploySalt: "0x",
signatory,
});
note

The number of signers in the signatories must be at least equal to the threshold for valid signature generation.