- React
- NodeJS
Privy’s ConnectedStandardSolanaWallet object is fully compatible with popular web3 libraries for interfacing wallets and signing transactions and messages, such as
@solana/kit.Read below to learn how to best integrate Privy alongside @solana/kit.First find your desired wallet from the wallets array:Report incorrect code
Copy
Ask AI
import {useWallets} from '@privy-io/react-auth/solana';
const {wallets} = useWallets();
const wallet = wallets[0]; // Replace this with your desired wallet
Signing Transactions
Transactions generated by@solana/kit can be signed using the signTransaction method from the useStandardSignTransaction hook.Report incorrect code
Copy
Ask AI
import {
pipe,
createTransactionMessage,
setTransactionMessageFeePayer,
setTransactionMessageLifetimeUsingBlockhash,
appendTransactionMessageInstructions,
compileTransaction,
createNoopSigner,
createSolanaRpc,
getTransactionEncoder
} from '@solana/kit';
import {getTransferSolInstruction} from '@solana-program/system';
import {useStandardSignTransaction} from '@privy-io/react-auth/solana';
const {signTransaction} = useStandardSignTransaction();
const LAMPORTS_PER_SOL = 1_000_000_000;
const transferInstruction = getTransferSolInstruction({
amount: LAMPORTS_PER_SOL * 1,
destination: address(to),
source: createNoopSigner(address(wallet.address))
});
const {getLatestBlockhash} = createSolanaRpc('YOUR_SOLANA_RPC_URL');
const {value: latestBlockhash} = await getLatestBlockhash().send();
// Create transaction
const transaction = pipe(
createTransactionMessage({version: 0}),
(tx) => setTransactionMessageFeePayer(address(wallet.address), tx),
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
(tx) => appendTransactionMessageInstructions([transferInstruction], tx),
(tx) => compileTransaction(tx)
);
const encodedTransaction = getTransactionEncoder().encode(transaction);
// Sign the transaction
const signedTransaction = await signTransaction({
transaction: new Uint8Array(encodedTransaction),
wallet: wallet
});
Sending Transactions
Transactions signed using thesignTransaction method can be sent using the signAndSendTransaction method from the useStandardSignAndSendTransaction hook.Report incorrect code
Copy
Ask AI
import {useStandardSignAndSendTransaction} from '@privy-io/react-auth/solana';
const {signAndSendTransaction} = useStandardSignAndSendTransaction();
const signature = await signAndSendTransaction({
transaction: new Uint8Array(transaction), // The transaction to send, from the previous example
wallet: wallet
}).signature;
Privy’s wallets on Solana natively integrate with Then, use Privy’s
@solana/kit via the
@privy-io/node SDK, allowing you to use the library’s signer interfaces for
signing messages and transactions, as well as sending those transactions to the
blockchain.Setup
To integrate with@solana/kit, first install the library as a peer dependency:Report incorrect code
Copy
Ask AI
npm i @solana/kit
createSolanaKitSigner method to initialize a signer for a Solana
wallet.
To this method, pass the following fields:The ID of the wallet to sign with.
The address of the wallet to sign with.
The authorization context for the wallet. Refer to the authorization
context guide for more details.
The CAIP-2 identifier for the Solana network. This is only required when sending transactions with
the Signer.
Example usage
As an example, you can initialize a signer like so:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/node';
import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
import {address} from '@solana/kit';
// Set up the Privy client and signer
const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
const signer = createSolanaKitSigner(privy, {
walletId: 'insert-wallet-id',
address: address('insert-wallet-address')
});
If your wallet requires an authorization context,
you should pass it to the
createSolanaKitSigner method like so, and it will be used
throughout the lifetime of the signer:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/node';
import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
import {address} from '@solana/kit';
// Set up the Privy client and signer
const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
const signer = createSolanaKitSigner(privy, {
walletId: 'insert-wallet-id',
address: address('insert-wallet-address'),
authorizationContext: {
authorization_private_keys: ['authorization-key']
}
});
Signing messages
You can sign messages using helper functions provided by@solana/kit, or by calling the signMessages method directly:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/node';
import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
import {address, signOffchainMessageWithSigners, type OffchainMessage} from '@solana/kit';
// Set up the Privy client and signer
const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
const signer = createSolanaKitSigner(privy, {
walletId: 'insert-wallet-id',
address: address('insert-wallet-address')
});
const offchainMessage: OffchainMessage = {
version: 1,
content: 'Hello, world!',
requiredSignatories: [signer]
};
const signedEnvelope = await signOffchainMessageWithSigners(offchainMessage);
Signing transactions
You can sign transactions using@solana/kit’s transaction building utilities:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/node';
import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
import {
address,
createTransactionMessage,
pipe,
setTransactionMessageFeePayerSigner,
signTransactionMessageWithSigners
} from '@solana/kit';
// Set up the Privy client and signer
const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
const signer = createSolanaKitSigner(privy, {
walletId: 'insert-wallet-id',
address: address('insert-wallet-address')
});
const transactionMessage = pipe(
createTransactionMessage({version: 0}),
// This sets both the fee payer address *and* uses the underlying signer.
(m) => setTransactionMessageFeePayerSigner(signer, m)
// Add instructions, lifetime, etc.
);
const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
Signing and sending transactions
To sign and send transactions, you must provide thecaip2 parameter when creating the signer:Report incorrect code
Copy
Ask AI
import {PrivyClient} from '@privy-io/node';
import {createSolanaKitSigner} from '@privy-io/node/solana-kit';
import {
address,
createTransactionMessage,
pipe,
setTransactionMessageFeePayerSigner,
signAndSendTransactionMessageWithSigners
} from '@solana/kit';
// Set up the Privy client and signer
const privy = new PrivyClient({appId: 'your-app-id', appSecret: 'your-app-secret'});
const signer = createSolanaKitSigner(privy, {
walletId: 'insert-wallet-id',
address: address('insert-wallet-address'),
caip2: 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1' // Solana Devnet
});
// The signer can now be used with signAndSendTransactionMessageWithSigners
const transactionMessage = pipe(
createTransactionMessage({version: 0}),
(m) => setTransactionMessageFeePayerSigner(signer, m)
// Add instructions, lifetime, etc.
);
const signedTransaction = await signAndSendTransactionMessageWithSigners(transactionMessage);
Common CAIP-2 identifiers for Solana:
- Mainnet:
solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp - Testnet:
solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z - Devnet:
solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1

