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.
- Beacon
- Taquito
Example
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...
Example
import { TezosToolkit } from "@taquito/taquito"; import { BeaconWallet } from "@taquito/beacon-wallet"; import Logger from "../Logger"; const Tezos = new TezosToolkit("https://mainnet.api.tez.ie"); const wallet = new BeaconWallet({ name: "Beacon Docs Taquito" }); Tezos.setWalletProvider(wallet); try { await wallet.client.disconnect(); } catch (err: any) { logger.log("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:
removeAccount
: if the argumentaccountIdentifier
matches the active accountremoveAllAccounts
: always
Note: Only for WalletConnect,
clearActiveAccount
will also resets all transport references behaving similarly todisconnect
- Beacon
- Taquito
Example
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...
Example
import { TezosToolkit } from "@taquito/taquito"; import { BeaconWallet } from "@taquito/beacon-wallet"; const Tezos = new TezosToolkit("https://mainnet.api.tez.ie"); const wallet = new BeaconWallet({ name: "Beacon Docs Taquito" }); Tezos.setWalletProvider(wallet); await wallet.clearActiveAccount(); try { const account = await wallet.getPKH(); console.log("Active Account", account); } catch { console.log("No wallet connected"); }
Loading...