Go Gasless

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 addressesed 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 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, ENTRYPOINT_ADDRESS_V07 } from "@cometh/connect-sdk-4337";

const paymasterClient = await createComethPaymasterClient({
    transport: http(paymasterUrl),
    chain,
    rpcUrl,
    entryPoint: ENTRYPOINT_ADDRESS_V07
})

You'll then need to add 2 paymaster methods on your client creation: sponsorUserOperation and gasPrice.

const smartAccountClient = createSmartAccountClient({
    account: smartAccount,
    entryPoint: ENTRYPOINT_ADDRESS_V07,
    chain,
    bundlerTransport: http(bundlerUrl),
    middleware: {
      sponsorUserOperation: paymasterClient.sponsorUserOperation,
      gasPrice: paymasterClient.gasPrice,
    }
})

Here is the full overview:

import { ENTRYPOINT_ADDRESS_V07, 
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 rpcUrl = process.env.RPC_URL;

const smartAccount = await createSafeSmartAccount({
    apiKey,
    rpcUrl,
    chain: arbitrumSepolia,
    entryPoint: ENTRYPOINT_ADDRESS_V07,
});

const paymasterClient = await createComethPaymasterClient({
    transport: http(paymasterUrl),
    chain,
    rpcUrl,
    entryPoint: ENTRYPOINT_ADDRESS_V07
})
    
const smartAccountClient = createSmartAccountClient({
    account: smartAccount,
    entryPoint: ENTRYPOINT_ADDRESS_V07,
    chain,
    bundlerTransport: http(bundlerUrl),
    middleware: {
      sponsorUserOperation: paymasterClient.sponsorUserOperation,
      gasPrice: paymasterClient.gasPrice,
    }
})

// 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,
  }
);

Last updated