To sponsor gas fees for transactions on Solana, see our guide here.
To rely on Privy’s API to fill in the recentBlockhash field of the Solana transaction, pass in the dummy value 11111111111111111111111111111111 for the recentBlockhash field.
To send a transaction from a wallet using the React SDK, use the sendTransaction method from the useSendTransaction hook:
sendTransaction: (input: {
  transaction: SupportedSolanaTransaction;
  connection: Connection;
  uiOptions?: SendTransactionModalUIOptions;
  transactionOptions?: SendTransactionOptions;
  fundWalletConfig?: SolanaFundingConfig;
  address?: string;
}) => Promise<SolanaTransactionReceipt>

Usage

import {useSendTransaction, useSolanaWallets} from '@privy-io/react-auth/solana';
import {Connection, Transaction, VersionedTransaction, PublicKey, SystemProgram} from '@solana/web3.js';

// Inside your component
const { sendTransaction } = useSendTransaction();
const { wallets } = useSolanaWallets();

// Configure your connection to point to the correct Solana network
const connection = new Connection('https://api.mainnet-beta.solana.com'); // Replace with your Solana RPC endpoint

// Create your transaction (either legacy Transaction or VersionedTransaction)
const transaction = new Transaction(); // or new VersionedTransaction()

// Build and add your instructions to the transaction...
const transferInstruction = SystemProgram.transfer({
  fromPubkey: new PublicKey(wallets[0].address), // Replace with the sender's address
  toPubkey: new PublicKey('RecipientPublicKeyHere'), // Replace with the recipient's address
  lamports: 1000000 // Amount in lamports (1 SOL = 1,000,000,000 lamports)
});
transaction.add(transferInstruction);

// Fetch and set the latest blockhash
const latestBlockhash = await connection.getLatestBlockhash();
transaction.recentBlockhash = latestBlockhash.blockhash; // Replace with the latest blockhash

// Set your address as the fee payer
transaction.feePayer = new PublicKey(wallets[0].address); // Set fee payer

// Send the transaction
const receipt = await sendTransaction({
    transaction: transaction,
    connection: connection,
    address: wallets[0].address, // Optional: Specify the wallet to use for signing. If not provided, the first wallet will be used.
});

console.log("Transaction sent with signature:", receipt.signature);

Parameters

Returns

signature
string
The signature of the transaction.
signedTransaction
SupportedSolanaTransaction
The signed transaction.
parsedTransaction
ParsedTransactionWithMeta | null
The parsed transaction result.
fees
bigint
The fees paid for the transaction in lamports.
For complete examples of sending SOL and SPL tokens using Privy’s SDKs, check out the sending a SOL transaction recipe and the sending SPL tokens recipe.