Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 1.87 KB

SEND_A_MULTI_TX_AND_PAY_GAS_WITH_TOKEN.md

File metadata and controls

56 lines (48 loc) · 1.87 KB
Key Description
buildUseropDto Options for building a userOp
paymasterServiceData PaymasterOptions set in the buildUseropDto
import {
  encodeFunctionData,
  parseAbi,
  createWalletClient,
  http,
  createPublicClient,
} from "viem";
import { createSmartAccountClient } from "@biconomy/account";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { mainnet as chain } from "viem/chains";

const account = privateKeyToAccount(generatePrivateKey());
const signer = createWalletClient({ account, chain, transport: http() });
const smartAccount = await createSmartAccountClient({
  signer,
  bundlerUrl,
  paymasterUrl,
}); // Retrieve bundler and pymaster urls from dashboard

const preferredToken = "0x747A4168DB14F57871fa8cda8B5455D8C2a8e90a"; // USDC

const tx = {
  to: nftAddress,
  data: encodeFunctionData({
    abi: parseAbi(["function safeMint(address to) public"]),
    functionName: "safeMint",
    args: ["0x..."],
  }),
};

const buildUseropDto = {
  paymasterServiceData: {
    mode: PaymasterMode.ERC20,
    preferredToken,
  },
};

const { wait } = await smartAccount.sendTransaction(
  [tx, tx] /* Mint twice */,
  buildUseropDto
);

const {
  receipt: { transactionHash },
  userOpHash,
  success,
} = await wait();