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.- React
- React Native
- Swift
- Android
- Flutter
- NodeJS
- NodeJS (server-auth)
- Java
- REST API
- Rust
To send a transaction from a wallet using the React SDK, use the
signAndSendTransaction
method from the useSignAndSendTransaction
hook:Report incorrect code
Copy
Ask AI
signAndSendTransaction: (input: {
transaction: Uint8Array;
wallet: ConnectedStandardSolanaWallet;
chain?: SolanaChain;
options?: SolanaSignAndSendTransactionOptions & {
uiOptions?: SendTransactionModalUIOptions;
sponsor?: boolean;
};
}) => Promise<{ signature: Uint8Array }>
Usage
Report incorrect code
Copy
Ask AI
import {useSignAndSendTransaction, useWallets} from '@privy-io/react-auth/solana';
import {
pipe,
createSolanaRpc,
getTransactionEncoder,
createTransactionMessage,
setTransactionMessageFeePayer,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstructions,
compileTransaction,
address,
createNoopSigner
} from '@solana/kit';
import {getTransferSolInstruction} from '@solana-program/system';
// Inside your component
const {signAndSendTransaction} = useSignAndSendTransaction();
const {wallets} = useWallets();
const selectedWallet = wallets[0];
const amount = 1;
const transferInstruction = getTransferSolInstruction({
amount: BigInt(parseFloat(amount) * 1_000_000_000), // Convert SOL to lamports
destination: address('RecipientAddressHere'),
source: createNoopSigner(address(selectedWallet.address))
});
// Configure your RPC connection to point to the correct Solana network
const {getLatestBlockhash} = createSolanaRpc('https://api.mainnet-beta.solana.com'); // Replace with your Solana RPC endpoint
const {value: latestBlockhash} = await getLatestBlockhash().send();
// Create a transaction using @solana/kit
const transaction = pipe(
createTransactionMessage({version: 0}),
(tx) => setTransactionMessageFeePayer(address(selectedWallet.address), tx), // Set the message fee payer
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), // Set recent blockhash
(tx) => appendTransactionMessageInstructions([transferInstruction], tx), // Add your instructions to the transaction
(tx) => compileTransaction(tx), // Compile the transaction
(tx) => new Uint8Array(getTransactionEncoder().encode(tx)) // Finally encode the transaction
);
// Send the transaction
const result = await signAndSendTransaction({
transaction: transaction,
wallet: selectedWallet
});
console.log('Transaction sent with signature:', result.signature);
Parameters
Hide parameters
Hide parameters
The encoded transaction to be sent.
The Solana wallet to use for sending the transaction.
Type of all Solana chains supported by Privy.
options
SolanaSignAndSendTransactionOptions & {uiOptions?: SendTransactionModalUIOptions; sponsor?: boolean}
Additional options for sending the transaction.
Show child attributes
Show child attributes
Optional parameter to enable gas sponsorship for this transaction. Learn
more.
Returns
The signature of the transaction.
Sign and send all transactions
To sign and send multiple transactions in a single call, use thesignAndSendTransaction
method with multiple inputs:Report incorrect code
Copy
Ask AI
signAndSendTransaction(...inputs: SignAndSendTransactionInput[]): Promise<SignAndSendTransactionOutput[]>
Usage
Report incorrect code
Copy
Ask AI
import {useSignAndSendTransaction, useWallets} from '@privy-io/react-auth/solana';
import {
pipe,
createSolanaRpc,
getTransactionEncoder,
createTransactionMessage,
setTransactionMessageFeePayer,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstructions,
compileTransaction,
address,
createNoopSigner
} from '@solana/kit';
import {getTransferSolInstruction} from '@solana-program/system';
// Inside your component
const {signAndSendTransaction} = useSignAndSendTransaction();
const {wallets} = useWallets();
const selectedWallet = wallets[0];
const amount = 1; // Amount of SOL to send
const transferInstruction = getTransferSolInstruction({
amount: BigInt(amount * 1_000_000_000), // Convert SOL to lamports
destination: address('RecipientAddressHere'),
source: createNoopSigner(address(selectedWallet.address))
});
// Configure your RPC connection to point to the correct Solana network
const {getLatestBlockhash} = createSolanaRpc('https://api.mainnet-beta.solana.com'); // Replace with your Solana RPC endpoint
const {value: latestBlockhash} = await getLatestBlockhash().send();
// Create transactions using @solana/kit
const transactions = [
pipe(
createTransactionMessage({version: 0}),
(tx) => setTransactionMessageFeePayer(address(selectedWallet.address), tx), // Set the message fee payer
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), // Set recent blockhash
(tx) => appendTransactionMessageInstructions([transferInstruction], tx), // Add your instructions to the transaction
(tx) => compileTransaction(tx), // Compile the transaction
(tx) => new Uint8Array(getTransactionEncoder().encode(tx)) // Finally encode the transaction
),
pipe(
createTransactionMessage({version: 0}),
(tx) => setTransactionMessageFeePayer(address(selectedWallet.address), tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => appendTransactionMessageInstructions([transferInstruction], tx),
(tx) => compileTransaction(tx),
(tx) => new Uint8Array(getTransactionEncoder().encode(tx))
)
];
// Send multiple transactions
const results = await signAndSendTransaction(
{
transaction: transactions[0],
wallet: selectedWallet
},
{
transaction: transactions[1],
wallet: selectedWallet
}
);
console.log(
'Transactions sent with signatures:',
results.map((result) => result.signature.toString()).join(',')
);
Parameters
Hide parameters
Hide parameters
The encoded transaction to be sent.
The Solana wallet to use for sending the transaction.
Type of all Solana chains supported by Privy.
options
SolanaSignAndSendTransactionOptions & {uiOptions?: SendTransactionModalUIOptions; sponsor?: boolean}
Additional options for sending the transaction.
Show child attributes
Show child attributes
Optional parameter to enable gas sponsorship for this transaction. Learn
more.
UI options to customize the transaction request modal.
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.