Appearance
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 RPC request with a delegated wallet, use the PrivyClient
's walletApi.rpc
method. As a parameter to this method, pass the request to execute with the wallet.
tsx
const request = {
address: '4tFqt2qzaNsnZqcpjPiyqYw9LdRzxaZdX2ewPncYEWLA',
chainType: 'solana',
method: 'signTransaction',
params: {
transaction: ...insertTransactionObject,
},
};
const {data} = await privy.walletApi.rpc(request);
const signedTransaction = data.signedTransaction;
There are currently two supported Solana actions: signMessage
and signTransaction
.
The request
should be an object with one of the following sets of parameters:
Field | Type | Description |
---|---|---|
address | string | Address of the wallet to take actions with. |
chainType | 'solana' | Chain type of the wallet to take actions with. |
method | 'signTransaction' | RPC method to execute with the wallet. |
params | Object | Parameters for the RPC method to execute with the wallet. |
params.transaction | Transaction | VersionedTransaction | A transaction object from @solana/web3.js to sign with the wallet. |
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
TIP
In the request headers, make sure to include Privy's required authentication headers and headers that may be required for your app's delegated actions setup.
Body
In the body of the request, include the following:
Field | Type | Description |
---|---|---|
address | string | Address of the wallet to take actions with. |
chain_type | 'solana' | Chain type of the wallet to take actions with. |
method | 'signTransaction' | RPC method to execute with the wallet. |
params | Object | Parameters for the RPC method to execute with the wallet. |
params.transaction | string | An encoded string serializing the transaction 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:
Field | Type | Description |
---|---|---|
method | 'signTransaction' | The RPC method executed with the wallet. |
data | Object | Outputs for the RPC method executed with the wallet. |
data.signed_transaction | string | An encoded string serializing the signed transaction produced by the user's wallet. |
data.encoding | 'base64' | The encoding format for the returned signed_transaction . 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": "signTransaction",
"params": {
"transaction": "insert-base-64-encoded-serialized-transaction",
"encoding": "base64"
}
}'
A successful response will look like the following:
json
{
"method": "signTransaction",
"data": {
"signed_transaction": "base64-encoded-serialized-signed-transaction",
"encoding": "base64"
}
}