Function useDeploySmartAccount

  • Parameters

    Returns UseMutationResult<UserOpResponse, any, UseDeploySmartAccountProps, any>

    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.

    Mutation function args: UseDeploySmartAccountProps

    Example


    import { useDeploySmartAccount, useUserOpWait, Options } from "@biconomy/useAA"
    import { polygonAmoy } from "viem/chains"
    import { encodeFunctionData, parseAbi } from "wagmi"

    export 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"
    onClickFunc={deployTx}
    isLoading={isPending || waitIsLoading}
    />
    </ErrorGuard>
    );
    };