Skip to main content
Execute complex transactions with custom data and manage their lifecycle using Para.

Prerequisites

You need Web3 libraries configured with Para authentication.

Execute Raw Transactions

import { useParaEthersSigner, useParaEthersSendTransaction } from "@getpara/react-sdk";
import { ethers, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider("https://ethereum-sepolia-rpc.publicnode.com");

function ExecuteTransaction() {
  const { ethersSigner } = useParaEthersSigner({ provider });

  const {
    sendTransactionAsync,
    isPending,
    data: receipt,
  } = useParaEthersSendTransaction(ethersSigner);

  return (
    <div>
      <button
        onClick={() =>
          sendTransaction({
            to: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
            data: "0x",
            value: ethers.parseEther("0.01"),
          })
        }
        disabled={isPending}
      >
        {isPending ? "Executing..." : "Execute Transaction"}
      </button>
      {receipt && <p>Transaction: {receipt.hash}</p>}
    </div>
  );
}

Execute Contract Functions

import { useParaEthersSigner, useParaEthersWriteContract } from "@getpara/react-sdk";
import { JsonRpcProvider } from "ethers";

const CONTRACT_ABI = [
  "function setGreeting(string memory _greeting)",
  "function greet() view returns (string)"
];

const provider = new JsonRpcProvider("https://ethereum-sepolia-rpc.publicnode.com");

function ContractInteraction({ contractAddress }: { contractAddress: string }) {
  const { ethersSigner } = useParaEthersSigner({ provider });

  const {
    writeContractAsync,
    isPending,
    data: receipt,
  } = useParaEthersWriteContract(ethersSigner);

  return (
    <div>
      <button
        onClick={() =>
          writeContract({
            address: contractAddress,
            abi: CONTRACT_ABI,
            functionName: "setGreeting",
            args: ["Hello from Para!"],
          })
        }
        disabled={isPending}
      >
        {isPending ? "Updating..." : "Update Greeting"}
      </button>
      {receipt && <p>Transaction: {receipt.hash}</p>}
    </div>
  );
}

Next Steps