Appearance
Creating a Solana wallet
To create a Solana embedded wallet for your user, call the createSolanaWallet
method on your PrivyUser
instance.
dart
abstract class PrivyUser {
/// Creates a Solana embedded wallet for the user.
Future<Result<EmbeddedSolanaWallet>> createSolanaWallet();
}
If a wallet is successfully created for the user, an EmbeddedSolanaWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
- The user is not authenticated
- A user already has a Solana wallet
- If the network call to create the wallet fails
The Solana wallet
An EmbeddedSolanaWallet
is defined as follows:
dart
abstract class EmbeddedSolonaWallet {
/// The wallet's address.
final String address;
/// The chain ID.
final String? chainId;
/// Recovery method type.
final String? recoveryMethod;
/// HD wallet index.
final int hdWalletIndex;
/// Chain type - in this case ChainType.solana
final ChainType chainType;
// A hook to an EmbeddedSolanaWalletProvider instance for this wallet
final EmbeddedSolanaWalletProvider provider;
}
Using the wallet
Privy supports requesting signatures on messages and transactions from a user's Solana embedded wallet using the signMessage
RPC. To request a signature, get the Solana embedded wallet provider and call the signMessage
method on it with a base-64 encoded message to sign. If the signature is computed successfully, signMessage
will return it as a base64-encoded string.
dart
abstract class EmbeddedSolanaWalletProvider {
/**
* Request a signature on a Base64 encoded message or transaction
*
* @param message Base64 encoded message or transaction
* @return The Base64 encoded computed signature
*/
Future<Result<String>> signMessage(String message);
}
Example usage:
dart
// Get the current user
final user = privy.user;
// Check if the user is authenticated
if (user != null) {
// Retrieve the user's Solana wallet
final solanaWallet = user.embeddedSolanaWallets.first;
if (solanaWallet != null) {
// Sign a message
final result = solanaWallet.provider.signMessage("SGVsbG8hIEkgYW0gdGhlIGJhc2U2NCBlbmNvZGVkIG1l c3NhZ2UgdG8gYmUgc2lnbmVkLg==")
}
}
Retrieving a user's Solana wallets
To retrieve all of a user's Solana wallets:
- Ensure the user is authenticated
- Grab the user's Solana wallets.
dart
// Get the current user
final user = privy.user;
// Check if the user is authenticated
if (user != null) {
// Retrieve the user's Solana wallets
final solanaWallet = user.embeddedSolanaWallets;
}