Skip to content

Using wallets on Solana

You can use Privy server wallets to sign messages and execute transactions on Solana or any SVM-compatible networks.

Using the SDK

To execute a Solana action with a server wallet, use the PrivyClient's walletApi.rpc method. As a parameter to this method, pass the request to execute with the wallet.

tsx
const {data} = await privy.walletApi.rpc({
  walletId: 'insert-wallet-id'
  method: 'signTransaction',
  params: {
    transaction: ...insertTransactionObject,
  },
});
const signedTransaction = data.signedTransaction;

There are currently three supported Solana actions: signMessage, signTransaction, and signAndSendTransaction.

The request should be an object with one of the following sets of parameters:

FieldTypeDescription
walletIdstringUnique ID of the wallet to take actions with.
idempotencyKeystring(Optional) Idempotency key to identify a unique request.
method'signMessage'RPC method to execute with the wallet.
paramsObjectParameters for the RPC method to execute with the wallet.
params.messagestring | Uint8ArrayThe string or bytes to sign with the wallet.

Using the REST API

To request a signature or transaction from a Solana wallet, make a POST request to:

sh
https://api.privy.io/v1/wallets/<wallet_id>/rpc

TIP

In the request headers, make sure to include Privy's required authentication headers and headers that may be required for your app's wallet API setup.

Body

In the body of the request, include the following fields. Make sure to follow the appropriate guidance for the action you'd like to take with the wallet (signing messages, signing transactions, or signing and broadcasting transactions).

FieldTypeDescription
method'signMessage'RPC method to execute with the wallet.
paramsObjectParameters for the RPC method to execute with the wallet.
params.messagestringAn encoded string serializing the message to be signed with the wallet.
params.encoding'base64'The encoding format for params.message. Currently, only 'base64' is supported.

Response

If the action is allowed, Privy will send the following fields in the response body:

FieldTypeDescription
method'signMessage'The RPC method executed with the wallet.
dataObjectOutputs for the RPC method executed with the wallet.
data.signaturestringAn encoded string serializing the signature produced by the user's wallet.
data.encoding'base64'The encoding format for the returned signature. Currently, only 'base64' is supported.

Examples

As an example, a sample request to take an action with a wallet might look like the following:

bash
$ 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 '{
  "method": "signMessage",
  "params": {
    "message": "insert-base-64-encoded-message",
    "encoding": "base64"
  }
}'

A successful response will look like the following:

json
{
  "method": "signMessage",
  "data": {
    "signature": "base64-encoded-signature",
    "encoding": "base64"
  }
}