Skip to main content

ZeroDev v0.9.0 Migration Guide

Version 0.9.0 introduces a unified UserOperation API that replaces the previous transaction-based APIs. The new API supports both single and batch transactions with a consistent interface.

Breaking Changes

The following functions have been removed:
  • estimateTransactionGas → Use estimateUserOperationGas
  • canSponsorTransaction → Use canSponsorUserOperation
  • prepareUserOperationWithKernelClient → Use sendUserOperation

New Features

  • Batch Transaction Support: Execute multiple operations atomically in a single UserOperation
  • Unified API: Consistent interface for single and batch transactions
  • Better Error Handling: More granular error types and messages

Migration Examples

Checking Sponsorship

Before (v0.8.x):
import { canSponsorTransaction } from "@dynamic-labs-sdk/zerodev";

const canSponsor = await canSponsorTransaction({
  walletAccount,
  transaction: {
    to: recipientAddress,
    value: parseEther("0.01"),
    data: "0x",
  },
});
After (v0.9.0):
import { canSponsorUserOperation } from "@dynamic-labs-sdk/zerodev";

const canSponsor = await canSponsorUserOperation({
  walletAccount,
  calls: [
    {
      to: recipientAddress,
      value: parseEther("0.01"),
      data: "0x",
    },
  ],
});
Key Changes:
  • Renamed from canSponsorTransaction to canSponsorUserOperation
  • transaction parameter → calls (array)
  • Single transaction now wrapped in an array

Estimating Gas

Before (v0.8.x):
import { estimateTransactionGas } from "@dynamic-labs-sdk/zerodev";

const gasEstimate = await estimateTransactionGas({
  walletAccount,
  transaction: {
    to: recipientAddress,
    value: parseEther("0.01"),
    data: "0x",
  },
});
After (v0.9.0):
import { estimateUserOperationGas } from "@dynamic-labs-sdk/zerodev";

const gasEstimate = await estimateUserOperationGas({
  walletAccount,
  calls: [
    {
      to: recipientAddress,
      value: parseEther("0.01"),
      data: "0x",
    },
  ],
});
Key Changes:
  • Renamed from estimateTransactionGas to estimateUserOperationGas
  • transaction parameter → calls (array)
  • Single transaction now wrapped in an array

Sending Transactions

Before (v0.8.x):
// No direct equivalent - you had to use prepareUserOperationWithKernelClient
// and manually send the operation
After (v0.9.0):
import { sendUserOperation } from "@dynamic-labs-sdk/zerodev";

const receipt = await sendUserOperation({
  walletAccount,
  calls: [
    {
      to: recipientAddress,
      value: parseEther("0.01"),
      data: "0x",
    },
  ],
});

console.log("Transaction successful:", receipt.userOpHash);
Key Changes:
  • New unified sendUserOperation function
  • Simplifies the send flow - no need for manual kernel client preparation
  • Returns complete receipt with userOpHash and success status

Batch Transaction Support

The new API’s main advantage is native batch transaction support:
import { sendUserOperation } from "@dynamic-labs-sdk/zerodev";

// Send multiple transactions atomically
const receipt = await sendUserOperation({
  walletAccount,
  calls: [
    { to: "0xRecipient1...", value: parseEther("0.1") },
    { to: "0xRecipient2...", value: parseEther("0.2") },
    { to: "0xRecipient3...", value: parseEther("0.3") },
  ],
});
Benefits:
  • Atomicity: All operations succeed or all fail together
  • Cost Efficiency: Single validation per batch reduces gas fees
  • Better UX: Users approve once for multiple operations
  • Composability: Enable complex multi-step workflows (e.g., approve + swap)

Migration Checklist

  • Replace canSponsorTransaction with canSponsorUserOperation
  • Replace estimateTransactionGas with estimateUserOperationGas
  • Replace manual UserOperation preparation with sendUserOperation
  • Update transaction parameter to calls array
  • Wrap single transactions in an array: calls: [transaction]
  • Update error handling for new error types
  • Test all transaction flows thoroughly
  • Consider using batch transactions for multi-step workflows