Skip to main content
This guide will demonstrate how to integrate Privy with Solana to enable wallet login as well as message and transaction signing.

Resources

Github starter repository

A starter repository for building an app with Privy and Solana.

Privy Solana Wallets

Privy Solana wallets can be a user’s EOA or an embedded wallet. This guide shows how to use them to sign messages and transactions.

Creating your Privy app

If you haven’t set up Privy yet, follow our React quickstart guide to get your app ID and configure your app.
Privy’s React SDK provides a secure way to authenticate users and manage wallets in your frontend application. Learn more about getting started with React.

Configuring Privy

For the Privy React SDK to work with Next.js using webpack, you need to add a custom webpack configuration. If you are not using Yarn, you can skip this step. Add the code below to your next.config.ts file:
In order to detect external Solana wallets, your app needs to enable Solana connectors. If you also wish to use Privy wallets to send transactions, then you must define solana RPC clients for Privy to use.
config.solana.rpcs is only required when using Privy’s embedded wallet UIs (UI signTransaction and signAndSendTransaction). If your app only uses external Solana wallets, you can omit the solana.rpcs configuration and prepare/send transactions directly via your chosen RPC client.

Using Privy in your app

With Privy now integrated into your app, you can leverage its hooks to authenticate users, generate embedded wallets, and facilitate message and transaction signing.

Log in with Privy

To log in users with Privy, you can use the useLogin hook from the @privy-io/react-auth package. This hook provides a function to log in users.

Creating a Solana embedded wallet

To create a Solana embedded wallet, you can use the useWallets hook from @privy-io/react-auth/solana. This hook provides a createWallet function to create an embedded wallet.

Using wallets

Privy provides the useSignMessage, useSignTransaction, and useSignAndSendTransaction hooks to sign messages and transactions with embedded wallets. You can also use linked EOA wallets directly for signing messages and transactions.

Signing a message

To sign a message with an embedded wallet, use the useSignMessage hook:
This function signs a message using the first embedded wallet.

Preparing a transaction

Before signing or sending a transaction, you need to prepare it. Here’s how you can create a simple SOL transfer transaction:
This code creates a transaction object that can be signed or sent later. Replace the placeholder values with actual addresses.

Signing a transaction

To sign a transaction, use the useSignTransaction hook:
This function signs the prepared transaction using the embedded wallet and a specified Solana RPC endpoint.

Sending a transaction

To send a signed transaction to the Solana network, use the useSignAndSendTransaction hook:
This function sends the signed transaction to the Solana network and logs the transaction signature.

Conclusion

This guide has shown you how to integrate Privy with Solana into an application. You can now log in users, create embedded wallets, and sign messages and transactions using the Privy React SDK.