The Arkena provider emits events when the wallet's state changes. Subscribe to them so your dApp reacts without polling.
The five events
| Event | When it fires | Payload |
|---|---|---|
accountsChanged | User switched accounts in the extension | string[] (new accounts) |
networkChanged | User switched between DevNet, TestNet, MainNet | string (new network) |
statusChanged | Wallet locked or unlocked | "locked" | "unlocked" |
disconnect | User revoked your origin's access | void |
txChanged | A transaction your dApp is awaiting changed status | { commandId, status } |
Subscription pattern
The provider follows the standard EIP-1193 subscription shape: on to
subscribe, removeListener to clean up.
"use client";
import { useEffect } from "react";
import { getArkenaProvider } from "@/lib/arkena";
export function useArkenaEvents(handlers: {
onAccountsChanged?: (accounts: string[]) => void;
onNetworkChanged?: (network: string) => void;
onDisconnect?: () => void;
}) {
useEffect(() => {
let provider: Awaited<ReturnType<typeof getArkenaProvider>>;
const onAccounts = (accounts: string[]) => handlers.onAccountsChanged?.(accounts);
const onNetwork = (network: string) => handlers.onNetworkChanged?.(network);
const onDisconnect = () => handlers.onDisconnect?.();
void getArkenaProvider().then((p) => {
provider = p;
if (!provider) return;
provider.on("accountsChanged", onAccounts);
provider.on("networkChanged", onNetwork);
provider.on("disconnect", onDisconnect);
});
return () => {
if (!provider) return;
provider.removeListener("accountsChanged", onAccounts);
provider.removeListener("networkChanged", onNetwork);
provider.removeListener("disconnect", onDisconnect);
};
}, [handlers.onAccountsChanged, handlers.onNetworkChanged, handlers.onDisconnect]);
}Recommended reactions
accountsChanged — refetch every user-scoped piece of state your
dApp holds: balances, activity, NFT gallery. Invalidate any cached SIWC
token (it was scoped to the previous account).
networkChanged — almost always remount the dApp. Different network
means different backend endpoint, different ledger state. Show a switching
indicator while you reload.
statusChanged — when the wallet locks, hide any signing-related
UI and show a "wallet locked" indicator. When it unlocks, restore.
disconnect — treat as logged-out. Clear the SIWC token, redirect
to your landing screen, show a Connect prompt.
txChanged — for any transaction whose commandId you're tracking,
update the UI. Optional but cheaper than polling.
What's next
- Provider events reference — the full payload shapes.
- Connect Button recipe — a worked example using two of these events.