# How to get the network a wallet is connected to?

**URL:** <https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638>\
**Category:** TypeScript SDK\
**Created:** [September 19, 2024, 1:39pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638 "2024-09-19T13:39:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [September 19, 2024, 1:39pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/1 "2024-09-19T13:39:57Z")

</div>

Dapps should check what network a wallet is connected to. Most dapps are using the fuel connectors. How to check if a wallet is connected to testnet or mainnet? The only way I see right now is to get `wallet.provider.url`, but it won’t work for custom urls such as different node providers or indexers. It looks like we should use `wallet.provider.getChainId()` for that, but that function right now returns `0` for all network (both for Fuel and Fuelet wallets)

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [September 19, 2024, 3:31pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/2 "2024-09-19T15:31:58Z")

</div>

Hi @mpoplavkov have you tried the [`currentNetwork`](https://docs.fuel.network/docs/fuels-ts/account/fuelconnector/#currentnetwork) method?

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [September 19, 2024, 4:19pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/3 "2024-09-19T16:19:49Z")

</div>

Got it, we need to take it from a connector instance, thanks

I’m trying to use this method:

```ts
        fuel.currentConnector()?.currentNetwork().then((network) => {
          console.log("Network", network.url);
          console.log("Chain", network.chainId);
        });

```

And I’m getting `undefined` for network.chainId for both Fuel wallet and Fuelet

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [September 19, 2024, 7:51pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/4 "2024-09-19T19:51:50Z")

</div>

@mpoplavkov typically you would use it in a fashion like this

```ts
  const fuel = await new Fuel({
      storage: null,
      connectors: [new MyConnector()],
    }).init();
    const [network] = await fuel.networks();
    const currentNetwork = await fuel.currentNetwork();
    expect(currentNetwork).toEqual(network);

```

Perhaps you could share a link to the repro of the issue so that we could take a look?

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [September 20, 2024, 12:01pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/5 "2024-09-20T12:01:18Z")

</div>

I’m using react hooks. That’s all I’m doing:

```ts
  const {fuel} = useFuel();
  const {isConnected} = useIsConnected();

  useEffect(() => {
    fuel.currentNetwork().then((network) => {
      console.log("Chain 1", network.chainId);
    });
    fuel.currentConnector()?.currentNetwork().then((network) => {
      console.log("Chain 2", network.chainId);
    });
  }, [isConnected, fuel]);

```

Both log outputs result in `network.chainId` to be `undefined`. Even when the wallet is connected, and the connector is set. Am I doing something wrong?

```auto
    "@fuels/connectors": "^0.27.1",
    "@fuels/react": "0.27.1",
    "fuels": "0.94.6",
    "react": "^18.2.0",

```

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [September 20, 2024, 7:54pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/6 "2024-09-20T19:54:03Z")

</div>

Hi @mpoplavkov that looks like correct usage, to be certain you could ensure that `console.log` is only called when `isConnected` is `true` but either way `useEffect` would re-trigger once `isConnected` changes, and thus you should see the network.

Could you share a link so that I could try and debug this issue?

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [September 23, 2024, 12:18pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/7 "2024-09-23T12:18:02Z")

</div>

I can’t, the repo is private. Just try to use the snippet I provided

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [September 23, 2024, 10:20pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/8 "2024-09-23T22:20:32Z")

</div>

Hi @mpoplavkov thanks for highlighting this, I was able to reproduce this issue on this [demo repo](https://github.com/maschad/connector-react-app) which is a modified fork of [https://connectors.fuel.network/](https://connectors.fuel.network/)

I’ve created this issue to address it with the [default fuel connectors](https://github.com/FuelLabs/fuel-connectors/issues/283) but the `chainId` returned is still `0`

I think this is a separate issue which I’m enquiring about at the moment.

EDIT: Once [this fix](https://github.com/FuelLabs/fuel-connectors/pull/284) is released you should get the correct `chainId`

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [September 24, 2024, 3:04pm UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/9 "2024-09-24T15:04:11Z")

</div>

Hi @mpoplavkov the fix has been released in [fuel-wallet](https://github.com/FuelLabs/fuels-wallet/releases/tag/v0.29.1) which will be released in the Chrome web store soon.

Feel free to test it though via [this link](https://next-wallet.fuel.network/app/fuel-wallet-0.29.1.zip)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [October 15, 2024, 11:04am UTC](https://forum.fuel.network/t/how-to-get-the-network-a-wallet-is-connected-to/6638/10 "2024-10-15T11:04:55Z")

</div>

Closed on October 15, 2024, 11:04am UTC

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
