Skip to content

Revoking delegated wallets

Once a user has delegated their wallets, they may also revoke delegations to prevent your app from taking any further wallet actions on their behalf.

You can revoke a user's delegated wallets with a revocation screen (with UIs) or automatically (without UIs).

To prompt users to revoke delegated wallets with a revocation screen, 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, 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>
  );
}