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.
Configuring Privy
Solana dependencies on yarn
Solana dependencies on yarn
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: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 theuseLogin
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 theuseWallets
hook from @privy-io/react-auth/solana
. This hook provides a createWallet
function to create an embedded wallet.
Using wallets
Privy provides theuseSignMessage
, 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 theuseSignMessage
hook:
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:Signing a transaction
To sign a transaction, use theuseSignTransaction
hook:
Sending a transaction
To send a signed transaction to the Solana network, use theuseSignAndSendTransaction
hook: