Skip to main content

Create a delegator 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 delegator account directly in your dapp.

Prerequisites

Create a delegator account using Viem SDK

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

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

import { http } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { sepolia as chain } from "viem/chains";

import {
Implementation,
createDeleGatorClient,
} from "@codefi/delegator-core-viem";

const transport = http();
const deploySalt = "0x1";

const privateKey = generatePrivateKey();
const owner = privateKeyToAccount(privateKey);

const client = createDeleGatorClient({
transport,
chain,
account: {
implementation: Implementation.Hybrid,
deployParams: [owner.address, [], [], []],
deploySalt,
isAccountDeployed: false,
signatory: owner,
},
});