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

Last updated