Skip to main content
function useEnableSpendPermissions(): UseEnableSpendPermissionsReturnType;
Hook that provides a wrapped function to retroactively enable spend permissions on an existing EVM Smart Account. This hook auto-resolves the smart account from the current authenticated user and surfaces both pre-polling and on-chain errors via the error return value.

Returns

UseEnableSpendPermissionsReturnType

Example

function EnableSpendPermissions() {
  const { enableSpendPermissions, data, error, status } = useEnableSpendPermissions();

  const handleEnableSpendPermissions = async () => {
    try {
      const result = await enableSpendPermissions({
        network: "base-sepolia",
        // evmSmartAccount: "0x..." // optional — auto-resolved from current user
      });
      console.log("User Operation Hash:", result.userOperationHash);
    } catch (error) {
      console.error("Failed to enable spend permissions:", error);
    }
  };

  return (
    <div>
      {status === "pending" && <p>Enabling spend permissions...</p>}
      {status === "success" && data && (
        <div>
          <p>Spend permissions enabled!</p>
          <p>Transaction Hash: {data.transactionHash}</p>
        </div>
      )}
      {status === "error" && <p>Error: {error?.message}</p>}
      <button onClick={handleEnableSpendPermissions}>
        Enable Spend Permissions
      </button>
    </div>
  );
}