To sponsor gas fees for transactions on Solana, see our guide here.
Use the signTransaction method exported from the useSignTransaction hook to sign a transaction with a Solana wallet.
signTransaction: (input: {
  transaction: SupportedSolanaTransaction;
  wallet: ConnectedStandardSolanaWallet;
  options?: SolanaSignTransactionOptions & {uiOptions?: SendTransactionModalUIOptions};
}) =>
  Promise<{
    signedTransaction: Uint8Array;
  }>;

Usage

import {useSignTransaction, useWallets} from '@privy-io/react-auth/solana';
import {pipe, createSolanaRpc, getTransactionEncoder, createTransactionMessage} from '@solana/kit';

// Inside your component
const {signTransaction} = useSignTransaction();
const {wallets} = useWallets();

const selectedWallet = wallets[0];

// Configure your connection to point to the correct Solana network
const {getLatestBlockhash} = createSolanaRpc('https://api.mainnet-beta.solana.com');

// Get the latest blockhash
const {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 transaction
const signedTransaction = await signTransaction({
  transaction: transaction,
  wallet: selectedWallet
});

console.log('Transaction signed successfully');

Parameters

transaction
Uint8Array
required
The encoded transaction to be signed.
wallet
ConnectedStandardSolanaWallet
required
The Solana wallet to use for signing the transaction.
chain
SolanaChain
Type of all Solana chains supported by Privy.
options
SolanaSignTransactionOptions & {uiOptions?: SendTransactionModalUIOptions}
Additional options for signing the transaction.

Response

signedTransaction
Uint8Array
The signed transaction that can be sent to the network.