Appearance
Revoking delegations
INFO
Users can revoke wallet delegation directly. To enable this, revocation is handled via Privy's React SDK which runs on the user's device.
To allow users to revoke consent to delegated actions, please first follow this guide to integrate @privy-io/react-auth
into your app's frontend.
Once a user has granted consent to delegated actions, they may also revoke consent to prevent your app from taking any further wallet actions on their behalf.
To revoke consent for delegated actions, use the revokeWallets
method from the useDelegatedActions
hook:
tsx
import {useDelegatedActions} from '@privy-io/react-auth';
...
const {revokeWallets} = useDelegatedActions();
When invoked, the revokeWallets
method will open a Privy modal where the user can either confirm the revocation of their delegated wallets. If the user has no delegated wallets, this method will error.
Once a user confirms revocation, Privy will flush the shares for the user's delegated wallets from the TEE-based cryptosystem, and your app will no longer be able to take actions on behalf of the user with their wallet unless the user delegates actions again.
If a user has delegated multiple embedded wallets, they will all be revoked.
As an example, you might have a button within your app to allow users to revoke delegated actions like so:
tsx
import {usePrivy, useDelegatedActions, type WalletWithMetadata} from '@privy-io/react-auth';
function RevokeDelegateActionButton() {
const {user} = usePrivy();
const {revokeWallets} = useDelegatedActions();
// Check if the user has any delegated wallets by searching the linkedAccounts array for wallets
// with `delegated: true` set
const hasDelegatedWallets =
user.linkedAccounts.filter(
(account): account is WalletWithMetadata => account.type === 'wallet' && account.delegated,
).length !== 0;
const onRevoke = async () => {
if (!hasDelegatedWallets) return; // Button is disabled to prevent this case
await revokeWallets();
};
return (
<button disabled={!hasDelegatedWallets} onClick={onRevoke}>
Revoke permission for this app to transact on my behalf
</button>
);
}