Configure your chosen Web3 library. You can use either a hook-based approach for React applications or a direct client setup for non-React environments or if you want to access the client outside of the ParaProvider context.
useEthers.ts
Copy
Ask AI
import { useClient, useAccount } from "@getpara/react-sdk";import { ParaEthersSigner } from "@getpara/ethers-v6-integration";import { ethers } from "ethers";import { useMemo } from "react";export function useEthers(rpcUrl: string = "https://ethereum-sepolia-rpc.publicnode.com") { const para = useClient(); const { isConnected, embedded } = useAccount(); const clients = useMemo(() => { // Create a provider connected to your RPC endpoint const provider = new ethers.JsonRpcProvider(rpcUrl); // Check if Para is initialized and user has wallets if (!para || !isConnected || !embedded.wallets?.length) { return { provider, signer: null }; } // Filter for EVM-compatible wallets const evmWallets = embedded.wallets.filter(w => w.type === "EVM"); if (evmWallets.length === 0) { return { provider, signer: null }; } // Create Para-enabled signer for transaction signing const signer = new ParaEthersSigner(para, provider); return { provider, signer }; }, [para, isConnected, embedded.wallets, rpcUrl]); return clients;}