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
  • Paymaster client
  1. CORE FEATURES

Go Gasless

PreviousSend transactionsNextSign/Verify a message

Last updated 1 month ago

With Cometh Connect, you can pay the transaction gas fees of your users. You will need to add the contract address of your transaction as a sponsored address for your project. Remember, the contract address corresponds to the "to" field of your transaction.

To authorize the sponsorship of a given contract address, you need to add it to your sponsored addresses in the dashboard. From there, we will accept sponsoring transactions targeting this contract.

At the end of each month, you will receive an invoice with the total amount of gas fees covered. This fee is then billed through the payment method in your Cometh Connect account.

With Cometh Connect, there is no overhead on the price you pay. Depending on your license type, you have a max number of transactions you can sponsor each month.

More details about the Cometh paymaster API :

Paymaster client

You'll first need to instantiate a paymaster Client, you'll need to get a paymasterUrl from the cometh dashboard.

import { createComethPaymasterClient } from "@cometh/connect-sdk-4337";

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

You'll then need to add a paymaster methods on your client creation: getUserOperationGasPrice.

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

Here is the full overview:

import { createSafeSmartAccount, 
createSmartAccountClient,
createComethPaymasterClient } from "@cometh/connect-sdk-4337";
import { encodeFunctionData } from "viem";
import countContractAbi from "@/contract/counterABI.json";

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

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


const smartAccount = await createSafeSmartAccount({
    apiKey,
    publicClient,
    chain: arbitrumSepolia,
});

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

// Counter address that is sponsored
const COUNTER_CONTRACT_ADDRESS = "0x4FbF9EE4B2AF774D4617eAb027ac2901a41a7b5F";

const calldata = encodeFunctionData({
  abi: countContractAbi,
  functionName: "count",
});

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

🛠️
Paymaster API
Add a sponsored contract address