Connect 4337
Cometh ConnectCometh MarketplaceCometh Checkout
  • 🚀Quick start
    • What is Connect 4337
    • Getting started
    • Supported Networks
  • 🛠️CORE FEATURES
    • Create a Wallet
    • Send transactions
    • Go Gasless
    • Sign/Verify a message
    • Retrieve a wallet address
    • Handle owners
    • Import a safe into connect
  • 🥷ADVANCED
    • Session Keys
      • Tutorial
      • Policies
        • Sudo policy
        • Action policy
    • Social recovery
    • Add a passkey signer on a different OS
    • Capabilities
      • sendCalls
      • getCallsStatus
      • getCapabilities
      • grantPermissions
    • Other signers (Auth Providers)
      • EOA wallets (Metamask, Phantom...)
      • Magic signer
      • Web3Auth signer
      • Turnkey signer
      • Privy signer
  • 🔌Integrations
    • React hooks
      • ConnectProvider
      • useAccount
      • useConnect
      • useDisconnect
      • useGetGasPrice
      • useSendTransaction
      • useSignMessage
      • useVerifyMessage
      • useWriteContract
      • Handle owners
        • useRemoveOwner
        • useValidateAddDevice
        • useCreateNewSigner
        • useAddOwner
        • useGetOwners/EnrichedOwners
      • Session Keys
        • useGrantPermission
        • useSendPermission
        • useSessionKeyClient
        • useSessionKeySigner
      • Recovery
        • useIsRecoveryActive
        • useSetUpRecovery
        • useGetRecoveryRequest
        • useCancelRecoveryRequest
    • Mobile SDKs
      • IOS
      • Android
      • React Native
    • Wagmi
  • SDK Core
    • Signers (Auth Providers)
      • EOA wallets (Metamask, Phantom...)
      • Magic signer
      • Web3Auth signer
      • Turnkey signer
      • Privy signer
    • Handle owners
    • Capabilities
      • sendCalls
      • getCallsStatus
      • getCapabilities
  • SDK Session Keys
    • Setup Smart Account Client
    • Manage session keys
    • Policies
      • Sudo policy
      • Action policy
  • 📦Bundler
    • Bundler API
      • eth_sendUserOperation
      • eth_estimateUserOperationGas
      • eth_getUserOperationByHash
      • eth_getUserOperationReceipt
      • eth_supportedEntryPoints
  • 💳Paymaster
    • Paymaster API
  • 📖RESOURCES
    • Migrate from the connect legacy SDK
    • Connect Legacy SDKs (Unity, JS)
    • FAQ
Powered by GitBook
On this page
  • Create the Privy provider
  • Integration
  1. ADVANCED
  2. Other signers (Auth Providers)

Privy signer

PreviousTurnkey signerNextReact hooks

Last updated 2 months ago

is an embedded wallet provider that simplifies user onboarding for dApps, enabling seamless authentication and key management.

By integrating Privy with Connect 4337, you can use Privy as a signer to create and manage smart wallets while using Connect 4337 gas sponsorship, batched transactions, and more.

Create the Privy provider

Follow Privy’s , to set up the Privy provider in your app.

import { PrivyProvider } from '@privy-io/react-auth';
import {WagmiProvider} from '@privy-io/wagmi'; 
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import {createConfig} from '@privy-io/wagmi'; 

import { http } from "viem";
import { arbitrumSepolia } from "viem/chains";


const queryClient = new QueryClient(); 
 
const config = createConfig({ 
  chains: [arbitrumSepolia], 
  transports: { 
    [arbitrumSepolia.id]: http(), 
  }, 
}); 

<PrivyProvider
  appId={"<Privy-App-Id>"}
  config={{
    embeddedWallets: {
      createOnLogin: "all-users",
    },
  }}
>
   <QueryClientProvider client={queryClient}>
    <WagmiProvider config={config}>
        {children}
     </WagmiProvider>
  </QueryClientProvider>
</PrivyProvider>;
 

Integration

import { useWallets } from "@privy-io/react-auth";


const { wallets } = useWallets();
const embeddedWallet = wallets.find(
  (wallet) => wallet.walletClientType === "privy"
);

Use it with Connect 4337:

import {
    createComethPaymasterClient,
    createSafeSmartAccount,
    createSmartAccountClient,
    providerToSmartAccountSigner
} from "@cometh/connect-sdk-4337";
import { type Hex, type PublicClient, createPublicClient, http } from "viem";
import { arbitrumSepolia } from "viem/chains";


const apiKey = process.env.COMETH_API_KEY;
const bundlerUrl = process.env.4337_BUNDLER_URL;
const paymasterUrl = process.env.NEXT_PUBLIC_4337_PAYMASTER_URL;

if (!embeddedWallet) throw new Error("User does not have an embedded wallet");

const privyProvider = await embeddedWallet!.getEthereumProvider()
const signer = await providerToSmartAccountSigner(privyProvider);

const publicClient = createPublicClient({
    chain: arbitrumSepolia,
    transport: http(),
    cacheTime: 60_000,
    batch: {
        multicall: { wait: 50 },
    },
}) as PublicClient;

const smartAccount = await createSafeSmartAccount({
    apiKey,
    signer,
    chain: arbitrumSepolia,
    publicClient,
    smartAccountAddress //if smart account already exists
 });
 
const walletAddress = smartAccount.address

const paymasterClient = await createComethPaymasterClient({
    transport: http(paymasterUrl),
    chain: arbitrumSepolia,
    publicClient,
});

const smartAccountClient = createSmartAccountClient({
    account: smartAccount,
    chain: arbitrumSepolia,
    bundlerTransport: http(bundlerUrl, {
        retryCount: 5,
        retryDelay: 1000,
        timeout: 20_000,
    }),
    paymaster: paymasterClient,
    userOperation: {
        estimateFeesPerGas: async () => {
            return await paymasterClient.getUserOperationGasPrice();
        },
    },
});

In your app, set Privy's embedded wallet as the active wallet for wagmi by using the useWallets react hook (after).

🥷
Privy
quickstart guide
Privy login