Appearance
Creating a Solana wallet
To create a Solana embedded wallet for your user, call the createSolanaWallet
method on your PrivyUser
instance.
kotlin
public interface PrivyUser {
// Other privy user methods
public suspend fun createSolanaWallet(): Result<EmbeddedSolanaWallet>
// ...
}
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:
kotlin
public interface EmbeddedSolanaWallet {
// The wallet's address
public val address: String
// The chain id
public val chainId: String?
// Recovery method type
public val recoveryMethod: String?
// HD wallet index
public val hdWalletIndex: Int
// Chain type - in this case, ChainType.Ethereum
public val chainType: ChainType
// A hook to an EmbeddedSolanaWalletProvider instance for this wallet
public val provider: EmbeddedSolanaWalletProvider
}
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.
kotlin
public interface EmbeddedSolanaWalletProvider {
/**
* Request a signature on a Base64 encoded message or transaction
*
* @param message Base64 encoded message or transaction
* @return The Base64 encoded computed signature
*/
public suspend fun signMessage(message: String): Result<String>
}
Example usage:
kotlin
// Get current auth state
val user = privy.user
// check if user is authenticated
if (user != null) {
// Retrieve list of user's Solana wallet
val solanaWallet = user.embeddedSolanaWallets.first()
if (solanaWallet != null) {
// Sign a message
val result = solanaWallet.provider.signMessage("SGVsbG8hIEkgYW0gdGhlIGJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UgdG8gYmUgc2lnbmVkLg==")
}
}
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.
kotlin
// Get current auth state
val user = privy.user
// check if user is authenticated
if (user != null) {
// Retrieve list of user's embedded Solana wallet
val solanaWallets = user.embeddedSolanaWallets
}