Skip to main content

createKernelClientForWalletAccount

Creates a ZeroDev KernelClient instance for a given smart wallet account. The KernelClient allows you to send user operations and interact with the smart account.

Usage

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)) {
  const kernelClient = await createKernelClientForWalletAccount({
    smartWalletAccount: walletAccount,
  });

  // Use the kernel client to send transactions
  const txHash = await kernelClient.sendTransaction({
    to: recipientAddress,
    value: parseEther("0.01"),
    data: "0x",
  });
}

Parameters

ParameterTypeDescription
smartWalletAccountEvmWalletAccountThe smart wallet account to create the KernelClient for
withSponsorshipboolean (optional)Whether to use gas sponsorship. Defaults to true
networkIdstring (optional)The network ID to use. If not provided, uses the active network
bundlerProviderZerodevBundlerProvider (optional)A custom bundler provider
bundlerRpcstring (optional)A custom bundler RPC URL
paymasterRpcstring (optional)A custom paymaster RPC URL
gasTokenAddressHex (optional)Address of an ERC20 token to use for gas payments
eip7702AuthSignAuthorizationReturnType (optional)A pre-signed EIP-7702 authorization. When provided, the kernel client uses this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need to separate the authorization signing step from the transaction step.
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<KernelClient> - A promise that resolves to a ZeroDev KernelClient instance.

Examples

With gas sponsorship (default)

const kernelClient = await createKernelClientForWalletAccount({
  smartWalletAccount: walletAccount,
});

Without gas sponsorship

const kernelClient = await createKernelClientForWalletAccount({
  smartWalletAccount: walletAccount,
  withSponsorship: false,
});

With custom gas token (ERC20)

const kernelClient = await createKernelClientForWalletAccount({
  smartWalletAccount: walletAccount,
  gasTokenAddress: "0x...", // USDC address
});

With specific network

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

With pre-signed EIP-7702 authorization

This is useful for singleUse MFA flows where you need to separate the authorization signing step from the transaction step:
import { signEip7702Authorization } from "@dynamic-labs-sdk/zerodev";

// First, sign the authorization separately
const eip7702Auth = await signEip7702Authorization({
  smartWalletAccount: walletAccount,
});

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