Skip to content

useDeploySmartAccount

Description

Deploys a users smartAccount contract. It is useful for deploying in a moment when you know that gas prices are low, and you want to deploy the account before sending the first user operation. This step can otherwise be skipped, as the deployment will alternatively be bundled with the first user operation.

Usage

import { useDeploySmartAccount, useUserOpWait, Options } from "@biconomy/use-aa";
import { polygonAmoy } from "viem/chains";
import { encodeFunctionData, parseAbi, Hex } from "viem";
import React, { useEffect } from "react"
 
const DeploySmartAccount = () => {
  const {
    mutate,
    data: userOpResponse,
    error,
    isPending,
  } = useDeploySmartAccount();
 
  const {
    isLoading: waitIsLoading,
    isSuccess: waitIsSuccess,
    error: waitError,
    data: waitData,
  } = useUserOpWait(userOpResponse);
 
  useEffect(() => {
    if (waitData?.success === "true") {
      console.log(waitData?.receipt?.transactionHash);
    }
  }, [waitData]);
 
  const deployTx = () =>
    mutate({
      options: Options.Sponsored,
    });
 
  return (
    <ErrorGuard errors={[error, waitError]}>
      <Button
        title="Deploy Smart Account"
        onClick={deployTx}
        isLoading={isPending || waitIsLoading}
      />
    </ErrorGuard>
  );
};
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2304. Expected: // @errors: 2304 Compiler Errors: index.tsx [2304] 753 - Cannot find name 'ErrorGuard'. [2304] 800 - Cannot find name 'Button'. [2304] 933 - Cannot find name 'ErrorGuard'.

Parameters

type UseDeploySmartAccountProps = {
  /** The BuildUserOpOptions options. See https://bcnmy.github.io/biconomy-client-sdk/types/BuildUserOpOptions.html for further detail */
  options?: BuildUserOpOptions;
};

Returns

type UserOpResponse = {
  userOpHash: string;
  wait(_confirmations?: number): Promise<UserOpReceipt>;
  waitForTxHash(): Promise<UserOpStatus>;
};

Source

hooks/useDeploySmartAccount.ts:69