Lens Blocks are currently in pre-alpha and not ready for use!

Use Tip Post Action Hook

A hook to tip Lens Posts using the Lens React SDK.

This hook allows users to tip a post using a specified payment source and amount.

Installation

Usage

import { useTipPostAction } from "@/hooks/use-tip-post-action";
import { usePost, useSessionClient, PaymentSource, postId, TxHash } from "@lens-protocol/react";
const { execute, error } = useTipPostAction();
const { data: sessionClient } = useSessionClient();
const { data: walletClient } = useWalletClient();
const post = postId("SOME_POST_ID");
const handleCreateTip = async (source: PaymentSource, amount: string, tokenAddress: string): Promise<TxHash> => {
  if (!sessionClient || !walletClient) {
    throw new Error("A valid session and wallet client are required");
  }

  const res = await execute({
    sessionClient,
    walletClient,
    post,
    source,
    amount,
    tokenAddress,
  });

  if (res.isErr()) {
    throw res.error;
  }

  return res.value;
};