Appearance
Getting a user's delegated wallets
From your server, you can query Privy to determine what wallets have been delegated by a given user to allow your app to take actions on their behalf.
Using @privy-io/server-auth
Use the Privy client's getUser
method to get the user object for your user. As a parameter to this method, pass the user's DID as a string
:
tsx
const user = await client.getUser('did:privy:insert-user-did');
Then, to get a list of the user's delegated wallets, first find all of the user's embedded wallets from the user's linked accounts. Simply filter the user.linkedAccounts
array for wallet entries with walletClientType: 'privy'
:
tsx
// The `WalletWithMetadata` type can be imported from '@privy-io/server-auth'
const embeddedWallets = user.linkedAccounts.filter(
(account): account is WalletWithMetadata =>
account.type === 'wallet' && account.walletClientType === 'privy',
);
Then, filter the array of embedded wallets for entries where the delegated
flag is set to true:
tsx
const delegatedWallets = embeddedWallets.filter((wallet) => wallet.delegated);
This constitutes the user's delegated wallets. Delegated wallets will always have the delegated
flag set to true
.
For wallets included in this array, your app may make requests to Privy to execute actions on Solana or EVM networks on behalf of the user.
Using the REST API
Make a GET
request to:
bash
https://auth.privy.io/api/v1/users/<did>
Replace <did>
with your desired Privy DID. It should have the format did:privy:XXXXXX
.
Below is a sample cURL command for this request:
bash
curl --request GET https://auth.privy.io/api/v1/users/<user-did> \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>"
Then, to get a list of the user's delegated wallets, inspect the linked_accounts
field of the response body for all entries with the fields type: 'wallet'
and delegated: true
.