Function useSessionWithDistributedKey

  • Parameters

    Returns UseMutationResult<UserOpResponse, any, UseSessionWithDistributedKeyProps, any>

    Description

    Uses a previously created session (see: https://bcnmy.github.io/useAA/functions/useCreateSession.html) which sends transactions in the context of a users smart account.

    Mutation function args: UseSessionWithDistributedKeyProps

    Example

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

    export const UseSessionWithDistributedKey = ({ smartAccountAddress }) => {

    const {
    mutate,
    data: userOpResponse,
    error,
    isPending,
    } = useSessionWithDistributedKey();

    const {
    isLoading: waitIsLoading,
    isSuccess: waitIsSuccess,
    error: waitError,
    data: waitData,
    } = useUserOpWait(userOpResponse);

    const mintTx = () =>
    mutate({
    transactions: {
    to: "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e",
    data: encodeFunctionData({
    abi: parseAbi(["function safeMint(address _to)"]),
    functionName: "safeMint",
    args: [smartAccountAddress],
    }),
    },
    options: Options.Sponsored,
    smartAccountAddress
    });

    useEffect(() => {
    if (waitData?.success === "true") {
    console.log(waitData?.receipt?.transactionHash);
    }
    }, [waitData]);


    return (
    <ErrorGuard errors={[error, waitError]}>
    <Button
    title="Use Session to Mint"
    onClickFunc={mintTx}
    isLoading={isPending || waitIsLoading}
    />
    </ErrorGuard>
    );
    };