Skip to main content

Delegation Toolkit documentation

Embed MetaMask Smart Accounts into your dapp, enabling new user experiences.

Send a gasless transaction

MetaMask Smart Accounts support gas sponsorship, which simplifies onboarding by abstracting gas fees away from end users. You can use any paymaster service provider, such as Pimlico or ZeroDev, or plug in your own custom paymaster.

Prerequisites

Send a gasless transaction

The following example demonstrates how to use Viem's Paymaster Client to send gasless transactions. You can provide the paymaster client using the paymaster property in the sendUserOperation method, or in the Bundler Client.

In this example, the paymaster client is passed to the sendUserOperation method.

import { bundlerClient, smartAccount, paymasterClient } from "./config.ts";
import { parseEther } from "viem";

// Appropriate fee per gas must be determined for the specific bundler being used.
const maxFeePerGas = 1n;
const maxPriorityFeePerGas = 1n;

const userOperationHash = await bundlerClient.sendUserOperation({
account: smartAccount,
calls: [
{
to: "0x1234567890123456789012345678901234567890",
value: parseEther("1")
}
],
maxFeePerGas,
maxPriorityFeePerGas,
paymaster: paymasterClient,
});