Optional
Withdraws funds from Smart Account to a recipient (defaults to EOA)
Mutation function args: UseSendWithdrawalsProps
import { useSendWithdrawals, useUserOpWait, useSmartAccount } from "@biconomy/useAA"import { polygonAmoy } from "viem/chains"import { NATIVE_TOKEN_ALIAS } from "@biconomy/account"export const Withdraw = () => { const { smartAccountAddress } = useSmartAccount(); const { mutate, data: userOpResponse, error, isPending, } = useSendWithdrawals(); const { isLoading: waitIsLoading, isSuccess: waitIsSuccess, error: waitError, data: waitData, } = useUserOpWait(userOpResponse); useEffect(() => { if (waitData?.success === "true") { console.log(waitData?.receipt?.transactionHash); } }, [waitData]); const withdrawalHandler = () => mutate({ withdrawalRequests: [ { token: "0x747A4168DB14F57871fa8cda8B5455D8C2a8e90a" }, // omit the amount to withdraw the full balance { address: NATIVE_TOKEN_ALIAS, amount: BigInt(1) } ], options: Options.Sponsored, }); return ( <ErrorGuard errors={[error, waitError]}> <Button title="Withdraw" onClickFunc={withdrawalHandler} isLoading={isPending || waitIsLoading} /> </ErrorGuard> );}; Copy
import { useSendWithdrawals, useUserOpWait, useSmartAccount } from "@biconomy/useAA"import { polygonAmoy } from "viem/chains"import { NATIVE_TOKEN_ALIAS } from "@biconomy/account"export const Withdraw = () => { const { smartAccountAddress } = useSmartAccount(); const { mutate, data: userOpResponse, error, isPending, } = useSendWithdrawals(); const { isLoading: waitIsLoading, isSuccess: waitIsSuccess, error: waitError, data: waitData, } = useUserOpWait(userOpResponse); useEffect(() => { if (waitData?.success === "true") { console.log(waitData?.receipt?.transactionHash); } }, [waitData]); const withdrawalHandler = () => mutate({ withdrawalRequests: [ { token: "0x747A4168DB14F57871fa8cda8B5455D8C2a8e90a" }, // omit the amount to withdraw the full balance { address: NATIVE_TOKEN_ALIAS, amount: BigInt(1) } ], options: Options.Sponsored, }); return ( <ErrorGuard errors={[error, waitError]}> <Button title="Withdraw" onClickFunc={withdrawalHandler} isLoading={isPending || waitIsLoading} /> </ErrorGuard> );};
Description
Withdraws funds from Smart Account to a recipient (defaults to EOA)
Mutation function args: UseSendWithdrawalsProps
Example