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
  • Install
  • Setup
  • SDK Core Features
  • Specify contract addresses

SDK Core

This Core version of the Cometh Connect SDK 4337 provides the essential functions for managing smart accounts. It supports various authentication providers such as EOA, Magic, Web3Auth, Turnkey, and Privy, allowing developers to create and interact with smart accounts efficiently.

The Core SDK does not require an API key. However, some advanced features, such as the Cometh Passkey signer, are not available in this version.

Install

npm i @cometh/connect-core-sdk viem

Setup

import { 
    createComethPaymasterClient, 
    createSafeSmartAccount, 
    createSmartAccountClient,
    providerToSmartAccountSigner
} from "@cometh/connect-core-sdk";
import { arbitrumSepolia } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
import { http } from "viem";

const bundlerUrl = process.env.NEXT_PUBLIC_4337_BUNDLER_URL;
const paymasterUrl = process.env.NEXT_PUBLIC_4337_PAYMASTER_URL;

const signer = await providerToSmartAccountSigner(
    window.ethereum
);

const publicClient = createPublicClient({
    chain: arbitrumSepolia,
    transport: http(),
    cacheTime: 60_000,
    batch: {
        multicall: { wait: 50 },
    },
});
​
const smartAccount = await createSafeSmartAccount({
    chain: arbitrumSepolia,
    publicClient,
    signer,
})

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

 const smartAccountClient = createSmartAccountClient({
    account: smartAccount,
    chain,
    bundlerTransport: http(bundlerUrl),
    paymaster: paymasterClient,
    userOperation: {
        estimateFeesPerGas: async () => {
            return await paymasterClient.getUserOperationGasPrice();
        },
    }
})

SDK Core Features

Send a transaction

import { smartAccountClient } from "./client";
import countContractAbi from "../contract/counterABI.json";

const calldata = encodeFunctionData({
    abi: countContractAbi,
    functionName: "count",
});
  
const txHash =  await smartAccountClient.sendTransaction({
    to: COUNTER_CONTRACT_ADDRESS,
    data: calldata,
});

Send batch transactions

const txHash =  await smartAccountClient.sendTransaction({
calls: [
      {
        to: COUNTER_CONTRACT_ADDRESS,
        data: calldata,
      },
      {
        to: COUNTER_CONTRACT_ADDRESS,
        data: calldata,
      },
    ],
});

Sign a message

const signature = await smartAccountClient.signMessage({message: "Hello world"});

Encode contract calls

const encodeCalls = await smartAccount.account.encodeCalls([
    {
        to: COUNTER_CONTRACT_ADDRESS,
        data: encodeFunctionData({
            abi: countContractAbi,
            functionName: "count",
        }),
    },
]);

Specify contract addresses

By default, the SDK Core uses the following contract addresses:

const defaultSafeContractConfig = {
    safeProxyFactoryAddress: "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
    safeSingletonAddress: "0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",
    multisendAddress: "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
    setUpContractAddress: "0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47",
    safe4337ModuleAddress: "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226",
};

If you want to specify custom contract addresses, you can pass the safeContractConfig parameter when creating a smart account:

const smartAccount = await createSafeSmartAccount({
    chain: arbitrumSepolia,
    publicClient,
    signer,
    safeContractConfig
})

Type of safeContractConfig:

type SafeContractParams = {
  safeProxyFactoryAddress: Address;
  safeSingletonAddress: Address;
  multisendAddress: Address;
  setUpContractAddress: Address;
  safe4337ModuleAddress?: Address;
};
PreviousWagmiNextSigners (Auth Providers)

Last updated 1 month ago