Use the signTransaction method on the Solana client to sign a transaction with an Solana wallet.

signTransaction: (input: SolanaSignTransactionInputType) => Promise<SolanaSignTransactionResponseType>

Usage

import {
clusterApiUrl,
Connection,
LAMPORTS_PER_SOL,
PublicKey,
SystemProgram,
Transaction,
VersionedTransaction,
TransactionMessage
} from '@solana/web3.js';

const walletPublicKey = new PublicKey(wallet.address);
const connection = new Connection(clusterApiUrl('devnet'));
const instruction = SystemProgram.transfer({
fromPubkey: walletPublicKey,
toPubkey: new PublicKey(address),
lamports: value * LAMPORTS_PER_SOL
});

const {blockhash: recentBlockhash} = await connection.getLatestBlockhash();

const message = new TransactionMessage({
payerKey: walletPublicKey,
// Replace with your desired instructions
instructions: [instruction],
recentBlockhash
});

const yourSolanaTransaction = new VersionedTransaction(message.compileToV0Message());

// Get the signed transaction object from the response
const {signedTransaction} = await privy.walletApi.solana.signTransaction({
walletId: wallet.id,
transaction: yourSolanaTransaction
});

Parameters

walletId
string
required

The ID of the wallet to send the transaction from.

transaction
Transaction | VersionedTransaction
required

The transaction to sign. This can be either a legacy Transaction or a VersionedTransaction object from @solana/web3.js.

Returns

signedTransaction
string

The signed transaction.

encoding
'base64'

The encoding format for the returned signedTransaction. Currently, only 'base64' is supported for Solana.