This example showcases how to get started using Privy's React SDK inside a React + Vite application.
mkdir -p privy-react-starter && curl -L https://github.com/privy-io/privy-examples/archive/main.tar.gz | tar -xz --strip=2 -C privy-react-starter examples-main/privy-react-starter && cd privy-react-starternpm installCopy the example environment file and configure your Privy app credentials:
cp .env.example .envUpdate .env with your Privy app credentials:
# Vite Environment Variables (exposed to browser)
VITE_PRIVY_APP_ID=your_app_id_here
VITE_PRIVY_CLIENT_ID=your_client_id_here
VITE_PRIVY_SIGNER_ID=your_signer_id_hereImportant: Variables prefixed with VITE_ are exposed to the browser. Get your credentials from the Privy Dashboard.
npm run devOpen http://localhost:5173 in your browser to see the application.
Login or sign up using Privy's pre-built modals.
import { usePrivy } from "@privy-io/react-auth";
const { login } = usePrivy();
login();Programmatically create embedded wallets for multiple blockchains.
src/components/create-wallet-card.tsx
import { useCreateWallet, useSolanaWallets } from "@privy-io/react-auth";
import { useCreateWallet as useCreateWalletExtendedChains } from "@privy-io/react-auth/extended-chains";
const { createWallet: createWalletEvm } = useCreateWallet();
const { createWallet: createWalletSolana } = useSolanaWallets();
const { createWallet: createWalletExtendedChains } =
useCreateWalletExtendedChains();
// Create Ethereum wallet
createWalletEvm({ createAdditional: true });
// Create Solana wallet
createWalletSolana({ createAdditional: true });
// Create Bitcoin/other chain wallets
createWalletExtendedChains({ chainType: "bitcoin-segwit" });Send transactions on both Ethereum and Solana.
src/components/wallet-actions-card.tsx
import { useSendTransaction } from "@privy-io/react-auth";
import { useSendTransaction as useSendTransactionSolana } from "@privy-io/react-auth/solana";
const { sendTransaction: sendTransactionEvm } = useSendTransaction();
const { sendTransaction: sendTransactionSolana } = useSendTransactionSolana();
// Send Ethereum transaction
const txHash = await sendTransactionEvm(
{ to: "0xE3070d3e4309afA3bC9a6b057685743CF42da77C", value: 10000 },
{ address: walletsEvm[0]?.address }
);
// Send Solana transaction
const receipt = await sendTransactionSolana({
transaction: transaction,
connection: connection,
address: walletsSolana[0].address,
});