Skip to main content

Configure the MetaMask Delegation Toolkit

The MetaMask Delegation Toolkit enables you to easily integrate MetaMask delegator accounts into your dapp, enabling a more flexible, secure, and frictionless experience for your users.

The toolkit is highly configurable, allowing you to tailor it to your project's specific needs. It includes support for custom signers, multiple signatory schemes, custom paymasters and bundlers, and more.

note

The MetaMask Delegation Toolkit provides custom middleware for Pimlico's gas fee resolver, paymaster, and bundler. Additional options will be made available soon.

Prerequisites

Viem's Account Abstraction API

The toolkit uses Viem's Account Abstraction API. This provides a robust and flexible foundation for creating and managing smart contract accounts. See Viem's Smart Account documentation for more information on the API's features, methods, and best practices.

Configure Viem bundler and paymaster clients

To use the bundler and paymaster clients with the toolkit, create instances of these clients and configure them as follows:

import {
createPaymasterClient,
createBundlerClient,
} from "viem/account-abstraction";
import { http } from "viem";
import { lineaSepolia as chain } from "viem/chains";

// Replace these URLs with your actual bundler and paymaster endpoints.
const bundlerUrl = "https://your-bundler-url.com";
const paymasterUrl = "https://your-paymaster-url.com";

// The paymaster is optional.
const paymasterClient = createPaymasterClient({
transport: http(paymasterUrl),
});

const bundlerClient = createBundlerClient({
transport: http(bundlerUrl),
paymaster: paymasterClient,
chain,
});
note

Providing a paymaster is optional when configuring your bundler client. However, if you choose not to use a paymaster, the smart contract account must have sufficient funds to pay for gas fees directly.