Extension Wallet
Integration
APTOS Network
Network

Network

This section explains how to retrieve the currently connected network from the Cosmostation wallet when using Aptos.

You can access network information either through the Aptos Wallet Adapter or via vanilla JavaScript using the injected provider.


Using Aptos Wallet Adapter

When using @aptos-labs/wallet-adapter-react, the useWallet() hook automatically keeps track of the wallet’s state, including the active network.

The network value is updated whenever the user changes networks inside the wallet UI.

Example

import { useWallet } from '@aptos-labs/wallet-adapter-react';
 
const { connected, network } = useWallet();
 
const getNetwork = async () => {
  try {
    if (!connected) {
      throw new Error('No connected wallet');
    }
 
    console.log('Current network:', network);
  } catch (error) {
    console.error(error);
  }
};

Behavior

  • network always reflects the wallet’s currently selected network
  • Network changes in the wallet are propagated automatically
  • No manual event subscription is required when using the adapter

Vanilla JavaScript

If you are not using the wallet adapter, you can query the network directly from the injected Aptos provider.

Example

try {
  const provider = aptos();
  const network = await provider.network();
 
  console.log('Current network:', network);
} catch (e) {
  if (e?.code === 4001) {
    console.log('User rejected the request');
  } else {
    console.error(e);
  }
}

Network API Specification

The vanilla network() method follows the Aptos Wallet Standard AptosGetNetworkMethod.

If you need the exact response structure and type definitions, refer to the official specification: