Appearance
Getting a user's delegated wallets
INFO
Users must consent to delegated actions directly from their device. In kind, delegation is handled via Privy's React SDK which runs on the user's device, in their browser.
To allow users to consent to delegated actions, please first follow this guide to integrate @privy-io/react-auth
into your app's frontend.
To get a list of embedded wallets for whom the user has granted your app delegated actions, 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
import {usePrivy, type WalletWithMetadata} from '@privy-io/react-auth';
...
const {user} = usePrivy();
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 embedded wallets that are not delegated, you may prompt users to delegate actions to your app to allow your app to execute certain transactions on their behalf.
For embedded wallets that are delegated, your app may execute wallet actions on the user's behalf within the set of permissions that the user has consented to. Alternatively, you may give users the option to revoke delegation to prevent your app from taking further actions on their behalf.