To sponsor gas fees for transactions on Solana, see our guide here.

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} from '@privy-io/react-auth/solana';
import {Connection, Transaction, VersionedTransaction} from '@solana/web3.js';

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

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

// Create your transaction (either legacy Transaction or VersionedTransaction)
const transaction = new Transaction(); // or new VersionedTransaction()
// Add your instructions to the transaction...

// Send the transaction
const receipt = await sendTransaction({
    transaction: transaction,
    connection: connection
});

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

Parameters

transaction
SupportedSolanaTransaction
required

The transaction to be sent. Can be either a legacy Transaction or VersionedTransaction from @solana/web3.js.

connection
Connection
required

Connection to an SVM (Solana) network.

uiOptions
SendTransactionModalUIOptions

UI options to customize the transaction request modal.

transactionOptions
SendTransactionOptions

Transaction options to customize the transaction request.

fundWalletConfig
SolanaFundingConfig

Funding configuration to specify cluster and funding amount (if enabled), in the case of insufficient funds.

address
string

Address for the embedded wallet sending the transaction. Defaults to the user’s embedded wallet at HD index 0.

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.