The useSignTransaction hook provides functionality to sign blockchain transactions with the user’s wallet.

Import

import { useSignTransaction } from "@getpara/react-sdk@alpha";

Usage

function TransactionSigner() {
  const { signTransactionAsync, isPending, error } = useSignTransaction();

  const handleSignTransaction = async () => {
    try {
      const tx = {
        to: "0x742d35Cc6634C0532925a3b844Bc9e7595f6E123",
        value: "0x2386f26fc10000", // 0.01 ETH in wei
        gasLimit: "0x5208", // 21000
        gasPrice: "0x09184e72a000", // 10000000000000
      };

      const rlpEncoded = encodeTransaction(tx); // Your encoding logic
      
      const result = await signTransactionAsync({
        rlpEncodedTxBase64: Buffer.from(rlpEncoded).toString("base64"),
      });

      if ("signature" in result) {
        console.log("Transaction signed:", result.signature);
      }
    } catch (err) {
      console.error("Failed to sign transaction:", err);
    }
  };

  return (
    <button 
      onClick={handleSignTransaction}
      disabled={isPending}
    >
      {isPending ? "Signing..." : "Sign Transaction"}
    </button>
  );
}