When using Privy’s server-side SDKs to sign transactions, you can use the authorization context to
automatically sign requests. Learn more about signing on the
server.
React
React Native
Swift
Android
Flutter
NodeJS
NodeJS (server-auth)
Java
Rust
REST API
Use the signTransaction method exported from the useSignTransaction hook to sign a transaction with a Solana wallet.
import {useSignTransaction, useWallets} from '@privy-io/react-auth/solana';import {pipe, createSolanaRpc, getTransactionEncoder, createTransactionMessage} from '@solana/kit';// Inside your componentconst {signTransaction} = useSignTransaction();const {wallets} = useWallets();const selectedWallet = wallets[0];// Configure your connection to point to the correct Solana networkconst {getLatestBlockhash} = createSolanaRpc('https://api.mainnet-beta.solana.com');// Get the latest blockhashconst {value} = await getLatestBlockhash().send();// Create your transaction (either legacy Transaction or VersionedTransaction)const transaction = pipe( createTransactionMessage({version: 0}), // Set the message fee payer... // Set recent blockhash... // Add your instructions to the transaction... // Finally encode the transaction (tx) => new Uint8Array(getTransactionEncoder().encode(tx)));// Sign the transactionconst signedTransaction = await signTransaction({ transaction: transaction, wallet: selectedWallet});console.log('Transaction signed successfully');