Here’s an example of how to sign a transaction on Solana with connected Solana external and embedded wallets:
Copy
Ask AI
import {PublicKey, Transaction, Connection, SystemProgram} from '@solana/web3.js';import {useSolanaWallets} from '@privy-io/react-auth';// The rest of this code must be placed within a React component// Get Solana walletconst {ready, wallets} = useSolanaWallets();const wallet = wallets[0];// Build transaction request. You should adapt this logic for the particular// type of transaction you need.if (!ready || !wallet) return;// Configure your connection to point to the correct Solana networklet connection = new Connection(clusterApiUrl('devnet'));// Build out the transaction object for your desired program// https://solana-foundation.github.io/solana-web3.js/classes/Transaction.htmllet transaction = new Transaction();// Sign transactionconst signedTransaction = await wallet.signTransaction!(transaction);console.log('Signed transaction:', signedTransaction);