Skip to main content

Disconnecting from a Wallet

This section explains all the available ways to disconnect a dApp in Beacon.

Disconnect

disconnect will only work while connected to a wallet, otherwise appropriate errors are thrown. It clears all transport references ensuring a clean and complete disconnection from the wallet.

Errors

Namely there are 3 errors that disconnect can throw which are:

  • "Syncing stopped manually.": This happens while disconnecting a P2P connection
  • "No transport available.": This happens when the transport hasn't resolved yet (likely because your dApp is not connected yet to a wallet)
  • "Not connected.": This error is thrown to prevent dApps from disconnecting multiple times.
Live Editor
import { DAppClient } from "@airgap/beacon-sdk";
const dAppClient = new DAppClient({ name: "Beacon Docs" });

dAppClient
  .disconnect()
  .then(() => {
    console.log("Disconnected.");
  })
  .catch((err) => console.error(err.message));
Loading...

ClearActiveAccount

clearActiveAccount manages the process of clearing the currently active account and only its associated active transport. This method ensures that all data linked to the active account is removed, and the active transport connection is terminated.

clearActiveAccount gets also invoked when calling:

  1. removeAccount: if the argument accountIdentifier matches the active account
  2. removeAllAccounts: always

Note: Only for WalletConnect, clearActiveAccount will also resets all transport references behaving similarly to disconnect

Live Editor
import { DAppClient } from "@airgap/beacon-sdk";
const dAppClient = new DAppClient({ name: "Beacon Docs" });

dAppClient
  .clearActiveAccount()
  .then(() => {
    const account = await dAppClient.getActiveAccount();
    console.log("Active Account", account);
  })
  .catch((err) => console.error(err.message));
Loading...