Extension Wallet
Integration
APTOS Network
Connect & Account

Connect, Account

Connecting is the first step in any wallet integration. In practice, connect() is a permission + session handshake between your dApp and the user’s wallet:

  • It prompts the user to approve the connection in the wallet UI.
  • Once approved, the wallet exposes the currently selected account to your dApp.
  • After you’re connected, you can safely call APIs like account(), signTransaction(), and signMessage() using the same standard interface.

If the user later changes the selected account inside the wallet, your dApp should treat account() as the source of truth and update UI state accordingly.

Note: disconnect() simply ends the active session/permission context from the dApp’s perspective. The wallet still exists in the browser; you’re just clearing the “connected” relationship and related state in your app.


Using Aptos Wallet Adapter

When you use @aptos-labs/wallet-adapter-react, the adapter handles wallet discovery and standardizes the connect lifecycle behind useWallet().

Example

import { WalletName, useWallet } from '@aptos-labs/wallet-adapter-react';
 
const { connect, disconnect, account, connected } = useWallet();
 
const handleConnect = async () => {
  try {
    await connect("Cosmostation Wallet" as WalletName<"Cosmostation Wallet">);
 
    // `connected` flips to true and `account` becomes available
    console.log('Connected:', connected);
    console.log('Account:', account);
  } catch (error) {
    console.error('Failed to connect:', error);
  }
};
 
const handleDisconnect = async () => {
  try {
    await disconnect();
    console.log('Disconnected');
  } catch (error) {
    console.error('Failed to disconnect:', error);
  }
};

Reference:


Vanilla Code

Cosmostation’s Aptos provider follows the Aptos Wallet Standard interface. This means you can call connect() directly on the injected provider without any adapter library.

Basic connect

// NOTE: `aptos()` helper is described in the Provider > Vanilla section
const provider = aptos();
 
try {
  const res = await provider.connect();
  console.log('connect response:', res);
} catch (e) {
  // Some wallets expose a "user rejected" code similar to other web wallet conventions
  if (e?.code === 4001) {
    console.log('User rejected the request');
    return;
  }
  console.error(e);
}

What does connect() return?

In the Aptos Wallet Standard, connect is defined as an AptosConnectMethod and its response is a UserResponse<AccountInfo> shape. (Source (opens in a new tab))

That means the wallet can respond in two ways:

  • Approvedstatus: "Approved" with args containing the connected AccountInfo
  • Rejectedstatus: "Rejected" (no args)

(Conceptually similar to a “user approved / user rejected” interaction.)

Recommended handling pattern

If your provider returns the standard UserResponse object (instead of throwing), handle both cases explicitly:

const provider = aptos();
 
const res = await provider.connect();
 
if (res?.status === 'Approved') {
  const accountInfo = res.args;
  console.log('Connected account:', accountInfo);
} else if (res?.status === 'Rejected') {
  console.log('User rejected the connection request');
}

Source reference

If you want to confirm the exact connect type definition and the AccountInfo model, see: