The below example shows full working code of a transaction being sponsored.

Note: The ‘useVp’ parameter is passed so that the system uses the deployed Verifying Paymaster that you deployed using developer dashboard if not it will error out as ‘Paymaster not deployed’ message. And by default, the value is false and will use EtherspotPaymaster contract which is only for EntryPoint v6

You must change the values in primeSdk.estimate() with your own API key.

import { ethers } from 'ethers';
import { PrimeSdk } from '../src';
import { printOp } from '../src/sdk/common/OperationUtils';
import * as dotenv from 'dotenv';
import { sleep } from '../src/sdk/common';

dotenv.config();

const ARKA_API_KEY = '' //  replace with your arka api key
const CHAIN_ID = 137; // replace with your desired chain id
const RECIPIENT = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const VALUE = '0.01'; // transfer value

async function main() {
  // initializing sdk...
  const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
    chainId: Number(CHAIN_ID),
  })

  console.log('address: ', primeSdk.state.walletAddress)

  // get address of EtherspotWallet...
  const address: string = await primeSdk.getCounterFactualAddress();
  console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);

  // clear the transaction batch
  await primeSdk.clearUserOpsFromBatch();

  // add transactions to the batch
  const transactionBatch = await primeSdk.addUserOpsToBatch({ to: RECIPIENT, value: ethers.utils.parseEther(VALUE) });
  console.log('transactions: ', transactionBatch);

  // get balance of the account address
  const balance = await primeSdk.getNativeBalance();

  console.log('balances: ', balance);

  // estimate transactions added to the batch and get the fee data for the UserOp
  const op = await primeSdk.estimate({
    paymasterDetails: {
      url: "https://rpc.etherspot.io/paymaster?apiKey=${ARKA_API_KEY}&chainId=${CHAIN_ID}&useVp=true",
      context: { mode: "sponsor" },
    },
  });  
  console.log(`Estimate UserOp: ${await printOp(op)}`); // 'printOp' is a helper function to print the UserOp which is imported from etherspot package

  // sign the UserOp and sending to the bundler...
  const uoHash = await primeSdk.send(op);
  console.log(`UserOpHash: ${uoHash}`);

  // get transaction hash...
  console.log('Waiting for transaction...');
  let userOpsReceipt = null;
  const timeout = Date.now() + 60000; // 1 minute timeout
  while ((userOpsReceipt == null) && (Date.now() < timeout)) {
    await sleep(2); // sleep 2 seconds
    userOpsReceipt = await primeSdk.getUserOpReceipt(uoHash);
  }
  console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}

main()
  .catch(console.error)
  .finally(() => process.exit());