Arkena Docs

Connect and disconnect

Request access, handle rejection, restore on mount, and clean up on disconnect.

Connection is the first interactive step in any dApp's relationship with the Arkena wallet. The user sees a popup with your origin and the permissions you're requesting; they accept or reject; you handle both.

  1. Request connection

    Code
    const result = await provider.request({ method: "canton_connect" });
    // result === { accounts: string[], network: "devnet" | "testnet" | "mainnet" }

    The user sees an approval popup with your origin (the scheme + host of the page making the request) and the permissions list. They click Approve or Reject.

    On accept, the promise resolves with the user's accounts and the network they're on. On reject, the promise rejects with an Error whose code is 4001.

  2. Handle rejection

    Code
    try {
      const result = await provider.request({ method: "canton_connect" });
      // ...use result
    } catch (err) {
      if (err && typeof err === "object" && "code" in err && err.code === 4001) {
        // User rejected — show a passive "Connect wallet" prompt, do not retry
        setStatus("disconnected");
      } else {
        throw err;
      }
    }

    Don't retry automatically on rejection. A user who said no doesn't want to be re-prompted three more times. Show a passive Connect button and let them try again on their schedule.

  3. Restore on mount

    The wallet remembers approved origins. Calling canton_connect on a page where the user has already approved this dApp resolves silently — no popup is shown.

    Use this on every mount: just call canton_connect. If the origin is already trusted you get the accounts back without UI; if not, the user sees the approval popup once.

    Code
    // On mount — safe to call unconditionally
    try {
      const { accounts, network } = await provider.request({
        method: "canton_connect",
      });
      setState({ status: "connected", accounts, network });
    } catch (err) {
      if ((err as { code?: number }).code === 4001) {
        setState({ status: "disconnected" });
      } else {
        throw err;
      }
    }

    If you'd rather not surface the popup automatically on first visit, gate the call behind a Connect button instead — same canton_connect call, just user-initiated.

  4. Disconnect

    Code
    await provider.request({ method: "canton_disconnect" });

    This revokes your origin's access. The wallet's stored permission for your site is cleared; the next canton_connect will show the popup again.

    The user can also disconnect from inside the extension (Settings → Connected sites). When they do, the wallet emits a disconnect event to your dApp — see Handle events.

What's next