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
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
});