Skip to content

Taking actions on Solana

Once a user has consented to delegated actions for their wallet, your app can take certain actions with the user's wallet.

Using @privy-io/server-auth

To execute a Solana action with a delegated wallet, use the methods on the PrivyClient's walletApi.solana class.

There are currently three supported Solana methods: signMessage, signTransaction, and signAndSendTransaction. View the parameters required for each method and examples below.

FieldTypeDescription
addressstringAddress of the wallet to take actions with.
chainType'solana'Chain type of the wallet to take actions with.
messagestring | Uint8ArrayThe string or bytes to sign with the wallet.
tsx
const {data} = await privy.walletApi.solana.signMessage({
  address: 'insert-address',
  chainType: 'solana',
  message: 'Hello world',
});
// Get the signature and encoding from the response
const {signature, encoding} = data;

TIP

If your app requests specific permissions, you cannot use the signMessage interface.

Using the REST API

To execute a Solana RPC request with a delegated wallet, make a POST request to:

bash
https://auth.privy.io/api/v1/wallets/rpc

Body

In the body of the request, include the following:

FieldTypeDescription
addressstringAddress of the wallet to take actions with.
chain_type'solana'Chain type of the wallet to take actions with.
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 for Solana.

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 for Solana.

Examples

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

bash
$ curl --request POST https://auth.privy.io/api/v1/wallets/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 '{
  "address": "4tFqt2qzaNsnZqcpjPiyqYw9LdRzxaZdX2ewPncYEWLA",
  "chain_type": "solana",
  "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"
  }
}