Skip to content

gelatodigital/safe-gelato-sdk-vs-safe-permisionless

Repository files navigation

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Migration Steps from Pimlico to Gelato

This project demonstrates how to migrate from Pimlico to Gelato for Safe Smart Account transactions. Below are the key changes required:

1. Changing Smart Account Client

Pimlico Implementation:

// Create Pimlico client
const pimlicoClient = createPimlicoClient({
  transport: http(process.env.NEXT_PUBLIC_PIMLICO_URL || ""),
  entryPoint: {
    address: entryPoint07Address,
    version: "0.7",
  },
});

// Create SmartAccountClient with Pimlico
const smartAccountClient = createSmartAccountClient({
  account,
  chain: baseSepolia,
  bundlerTransport: http(process.env.NEXT_PUBLIC_PIMLICO_URL || ""),
  paymaster: pimlicoClient,
  userOperation: {
    estimateFeesPerGas: async () => {
      return (await pimlicoClient.getUserOperationGasPrice()).fast;
    },
  },
});

Gelato Implementation:

// Create SmartAccountClient with Gelato
const smartAccountClient = createSmartAccountClient({
  account,
  chain: baseSepolia,
  // Important: Chain transport (chain rpc) must be passed here instead of bundler transport
  bundlerTransport: http(),
  userOperation: {
    estimateFeesPerGas: async () => {
      return getUserOperationGasPrice(baseSepolia.id, gelatoApiKey).then(
        ({ fast }) => fast
      );
    },
  },
}).extend(
  gelatoBundlerActions({
    payment: sponsored(),
    apiKey: gelatoApiKey,
    encoding: WalletEncoding.Safe,
  })
);

Key Changes:

  • Remove Pimlico client creation
  • Change bundlerTransport from Pimlico URL to chain RPC
  • Remove paymaster configuration
  • Add .extend(gelatoBundlerActions()) with Gelato-specific configuration
  • Use getUserOperationGasPrice from Gelato SDK instead of Pimlico client

2. sendTransaction to sendUserOperation

Pimlico Implementation:

const hash = await smartAccountClient.sendTransaction({
  calls: [
    {
      to: "0xEEeBe2F778AA186e88dCf2FEb8f8231565769C27",
      data: "0xd09de08a",
      value: BigInt(0),
    },
  ],
});

Gelato Implementation:

const userOpHash = await smartAccountClient.sendUserOperation({
  calls: [
    {
      to: "0xEEeBe2F778AA186e88dCf2FEb8f8231565769C27",
      data: "0xd09de08a",
      value: BigInt(0),
    },
  ],
});

// Wait for user operation receipt
const receipt = await smartAccountClient.waitForUserOperationReceipt({
  hash: userOpHash,
});
// Get transaction hash from receipt
const transactionHash = receipt.receipt.transactionHash;

Key Changes:

  • Change sendTransaction to sendUserOperation

3. Dependencies and Imports

Remove Pimlico imports:

// Remove this import
import { createPimlicoClient } from "permissionless/clients/pimlico";

Add Gelato imports:

import { sponsored, WalletEncoding } from "@gelatonetwork/smartwallet";
import {
  gelatoBundlerActions,
  getUserOperationGasPrice,
} from "@gelatonetwork/smartwallet/adapter";

Summary

The main differences in migrating from Pimlico to Gelato are:

  1. Client Creation: Replace Pimlico client with Gelato bundler actions
  2. Method Call: Change from sendTransaction to sendUserOperation
  3. Transaction Handling: Handle user operation hash and wait for receipt

About

safe-permisionless-vs-safe-gelato-sdk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published