Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt

Use this file to discover all available pages before exploring further.

Active Network id

The active network id is the id that the Dynamic SDK uses to identify the active network of a wallet account. For EVM wallets, it will be the same as the chain id (e.g: 1, 137, 56, etc). For other chains, it will an internal id used in Dynamic. To get a more complete network data, you can use the getActiveNetworkData function mentioned further down in this page.
import { getActiveNetworkId } from '@dynamic-labs-sdk/client';

const { networkId } = await getActiveNetworkId({ walletAccount });
console.log(networkId);

Active Network Data

The active Network Data is the data that the Dynamic SDK uses to identify the active network of a wallet account. The NetworkData object contains useful information about the network, such as the id, name, icon, rpc urls, currency data, etc. You can use the active network data create a PublicClient for EVM accounts or a Connection for Solana accounts.
import { getActiveNetworkData } from '@dynamic-labs-sdk/client';

const { networkData } = await getActiveNetworkData({ walletAccount });
console.log(activeNetworkData);

React

Both functions are async and are typically called inside useEffect or event handlers. Re-fetch whenever the active wallet or network changes:
import { getActiveNetworkData } from '@dynamic-labs-sdk/client';
import { onEvent } from '@dynamic-labs-sdk/client';
import { useEffect, useState } from 'react';

function ActiveNetworkDisplay({ walletAccount }) {
  const [networkData, setNetworkData] = useState(null);

  useEffect(() => {
    if (!walletAccount) return;

    const fetch = () =>
      getActiveNetworkData({ walletAccount }).then(({ networkData }) => setNetworkData(networkData));

    fetch();
    return onEvent('networkChanged', fetch);
  }, [walletAccount]);

  if (!networkData) return null;
  return <p>Active network: {networkData.name}</p>;
}