When using Privy’s server-side SDKs to sign messages, you can use the authorization context to
automatically sign requests. Learn more about signing on the
server.
- React
- React Native
- Swift
- Android
- Unity
- Flutter
- NodeJS
- NodeJS (server-auth)
- Java
- Rust
- REST API
Use the
signMessage method exported from the useSignMessage hook to sign a message with a Solana wallet.Report incorrect code
Copy
Ask AI
signMessage: ({
message,
options
}: {
message: Uint8Array;
wallet: ConnectedStandardSolanaWallet;
options?: {
uiOptions?: SignMessageModalUIOptions;
};
}) =>
Promise<{
signature: Uint8Array;
}>;
Usage
Report incorrect code
Copy
Ask AI
import {useWallets, useSignMessage} from '@privy-io/react-auth/solana';
import bs58 from 'bs58';
const {wallets} = useWallets();
const {signMessage} = useSignMessage();
const selectedWallet = wallets[0];
const message = 'Hello world';
const signatureUint8Array = (
await signMessage({
message: new TextEncoder().encode(message),
wallet: selectedWallet,
options: {
uiOptions: {
title: 'Sign this message'
}
}
})
).signature;
const signature = bs58.encode(signatureUint8Array);
Parameters
Message to be signed as a Uint8Array.
The Solana wallet to use for signing the message.
Response
The signature produced by the wallet.
The original message that was signed.
Request a message signature on the wallets Ethereum provider.
Report incorrect code
Copy
Ask AI
import {useEmbeddedSolanaWallet} from '@privy-io/expo';
const wallet = useEmbeddedSolanaWallet();
const provider = await wallet.getProvider();
const message = 'Hello world';
const {signature} = await provider.request({
method: 'signMessage',
params: {message}
});
Parameters
The method for the wallet request. For signing messages, this is
'signMessage'.Hide properties
Hide properties
The string to sign with the wallet. If the message is a string, you should pass the string as
the message directly. If the message is an array of bytes (Uint8Array), you should
base64-encode the array as a string before passing it to message.
The address of the wallet to sign the message with.
Returns
The signature produced by the wallet.
Request a message signature on the wallet’s Solana provider.
Report incorrect code
Copy
Ask AI
guard let user = privy.user else {
// If user is null, user is not authenticated
return
}
// Retrieve list of user's embedded Solana wallets
let solanaWallets = user.embeddedSolanaWallets
// Grab the desired wallet. Here, we retrieve the first wallet
guard let wallet = solanaWallets.first else {
// No SOL wallets
return
}
// Sign a Base64 encoded message
let signature = try await wallet.provider.signMessage(message: "SGVsbG8hIEkgYW0gdGhlIGJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UgdG8gYmUgc2lnbmVkLg==")
print("Result signature: \(signature)")
Parameters
The message to sign, as a base64-encoded string.
Returns
The signature produced by the wallet.
Use the
signMessage method on the Solana wallet provider to sign a message with the wallet.Report incorrect code
Copy
Ask AI
// 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==")
}
}
Parameters
The message to sign, as a base64-encoded string.
Returns
The signature produced by the wallet.
Usage
Report incorrect code
Copy
Ask AI
try {
IEmbeddedSolanaWallet embeddedWallet = PrivyManager.Instance.User.EmbeddedSolanaWallets[0];
IEmbeddedSolanaWalletProvider provider = embeddedWallet.EmbeddedSolanaWalletProvider;
string signature = await provider.SignMessage("A message to sign");
Debug.Log(signature);
} catch (PrivyException.EmbeddedWalletException ex){
Debug.LogError($"Could not sign message due to error: {ex.Error} {ex.Message}");
} catch (Exception ex) {
Debug.LogError($"Could not sign message exception {ex.Message}");
}
Parameters
The base64 encoded bytes of the message or transaction to sign.
Returns
The base64 encoded signature of the message, produced by the wallet.
Use the
signMessage method on the Solana wallet provider to sign a message with the wallet.Report incorrect code
Copy
Ask AI
// 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("SGVsbG8hIEkgYW0gdGhlIGJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UgdG8gYmUgc2lnbmVkLg==")
}
}
Parameters
The message to sign, as a base64-encoded string.
Returns
The signature produced by the wallet.
Use the
signMessage method on the solana interface to sign a message with an Solana wallet.Usage
Report incorrect code
Copy
Ask AI
const {signature, encoding} = await privy.wallets().solana().signMessage('insert-wallet-id', {
message: 'Hello world'
});
Parameters and Returns
Check out the API reference for more details.The
@privy-io/server-auth library is deprecated. We recommend integrating @privy-io/node for
the latest features and support.signMessage method on the ethereum client to sign a message with an Solana wallet.Report incorrect code
Copy
Ask AI
signMessage: (message: string, options: {uiOptions: SignMessageModalUIOptions; address?: string}) =>
Promise<{signature: string}>;
Usage
Report incorrect code
Copy
Ask AI
const {signature, encoding} = await privy.walletApi.solana.signMessage({
walletId: 'insert-wallet-id',
message: 'Hello world'
});
Parameters
Unique ID of the wallet to take actions with.
The string or bytes to sign with the wallet.
Idempotency key to identify a unique request.
Returns
An encoded string serializing the signature produced by the user’s wallet.
The encoding format for the returned
signature. Currently, only 'base64' is supported for
Solana.To sign a message from your wallet, use the
signMessage method.
It will sign your message, and return the signature to you.Usage
Report incorrect code
Copy
Ask AI
try {
// Base64 encoded message
String message = "SGVsbG8hIEkgYW0gdGhlIGJhc2U2NCBlbmNvZGVkIG1lc3NhZ2UgdG8gYmUgc2lnbmVkLg";
// Example: If wallet's owner is an authorization private key
AuthorizationContext authorizationContext = AuthorizationContext.builder()
.addAuthorizationPrivateKey("authorization-key")
.build();
SolanaSignMessageRpcResponseData response = privyClient
.wallets()
.solana()
.signMessage(
walletId,
message,
authorizationContext
);
String signature = response.signature();
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
When signing a message with your solana wallet, you can sign over a base64 string encoding.The base64 encoded message to sign over.
Returns
TheSolanaSignMessageRpcResponseData object contains a signature() fieldThe signature produced by the wallet.
Use the
sign_message method on the Solana service to sign a message with a Solana wallet.Usage
Report incorrect code
Copy
Ask AI
use privy_rs::{AuthorizationContext, PrivyClient};
let client = PrivyClient::new("app_id".to_string(), "app_secret".to_string())?;
let solana_service = client.wallets().solana();
let auth_ctx = AuthorizationContext::new();
// Base64 encode your message first
let message = base64::encode("Hello, Solana!");
let signature = solana_service
.sign_message(
&wallet_id,
&message,
&auth_ctx,
Some("unique-request-id-456"),
)
.await?;
println!("Message signed successfully");
Parameters and Returns
See the Rust SDK documentation for detailed parameter and return types, including embedded examples:For REST API details, see the API reference.To sign a message make a POST request to
Report incorrect code
Copy
Ask AI
https://api.privy.io/v1/wallets/<wallet_id>/rpc
Parameters
RPC method to execute with the wallet.
Parameters for the RPC method to execute with the wallet.
Returns
The RPC method executed with the wallet.
Usage
Report incorrect code
Copy
Ask AI
$ curl --request POST https://api.privy.io/v1/wallets/<wallet_id>/rpc \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "privy-authorization-signature: <authorization-signature-for-request>" \
-H 'Content-Type: application/json' \
-d '{
"chain_type": "solana",
"method": "signMessage",
"params": {
"message": "Hello, Solana.",
"encoding": "base64"
}
}'

