Skip to main content

signEip7702Authorization

Signs an EIP-7702 authorization for ZeroDev kernel delegation. This function creates a signed authorization that allows a wallet to delegate its execution to the ZeroDev kernel contract. The signed authorization can then be passed to createKernelClientForWalletAccount via the eip7702Auth parameter. This is useful for singleUse MFA flows where you need to separate the authorization signing step from the transaction step.

Usage

import { signEip7702Authorization } from "@dynamic-labs-sdk/zerodev";
import { createKernelClientForWalletAccount } from "@dynamic-labs-sdk/zerodev";
import { isEvmWalletAccount } from "@dynamic-labs-sdk/evm";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isEvmWalletAccount(walletAccount)) {
  // Sign the EIP-7702 authorization
  const eip7702Auth = await signEip7702Authorization({
    smartWalletAccount: walletAccount,
  });

  // Use the authorization when creating the kernel client
  const kernelClient = await createKernelClientForWalletAccount({
    smartWalletAccount: walletAccount,
    eip7702Auth,
  });
}

Parameters

ParameterTypeDescription
smartWalletAccountEvmWalletAccountThe EVM smart wallet account to sign the authorization for
networkIdstring (optional)The network ID to use for signing. If not provided, uses the wallet’s active network
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<SignAuthorizationReturnType> - A promise that resolves to the signed EIP-7702 authorization.

Examples

Basic usage

const eip7702Auth = await signEip7702Authorization({
  smartWalletAccount: walletAccount,
});

With specific network

const eip7702Auth = await signEip7702Authorization({
  smartWalletAccount: walletAccount,
  networkId: "137", // Polygon
});

With singleUse MFA flow

This pattern is useful when you need to sign the authorization during an MFA step, then use it later for the transaction:
import { signEip7702Authorization, createKernelClientForWalletAccount } from "@dynamic-labs-sdk/zerodev";

// Step 1: Sign authorization (can be done during MFA verification)
const eip7702Auth = await signEip7702Authorization({
  smartWalletAccount: walletAccount,
});

// Step 2: Later, create kernel client with pre-signed authorization
const kernelClient = await createKernelClientForWalletAccount({
  smartWalletAccount: walletAccount,
  eip7702Auth,
});

// Step 3: Send transaction
const txHash = await kernelClient.sendTransaction({
  to: recipientAddress,
  value: parseEther("0.01"),
  data: "0x",
});