Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[bug]: network changed: 1329 => 42161 even though I did not #494

@Crismon96

Description

@Crismon96

Description

Just sometimes, but always when I try to sign a TX with Metamask on a EVM compatible chain (SEIEVM). I get put into a loop:

=> Redirect to MM, Sign TX => Redirect to App => barrage of ERROR (see below) => Redirect to MM => Going back to app via navigation => Redirect to MM again

There is no way out of this loop. The logs tell me that the network apparently changed but I did not (just tried to sign a TX). Going back to the app always triggers the error again then and prompts to MM. Also the "Switch Network" Modal appears briefly before I get auto-redirected to MM again.

The Error:

 WARN  [MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 relayer_publish listeners added. Use emitter.setMaxListeners() to increase limit]
 ERROR  error:  [Error: Error: network changed: 1329 => 42161  (event="changed", code=NETWORK_ERROR, version=6.15.0)] 

Code: CollateralManagementModal.tsx
  885 |                     .addColl(tokenAmounts, upperHint, lowerHint, updateDataInBytes, { value: priceUpdateFee })
  886 |                     .catch((err: any) => {
> 887 |                       throw new Error(err, { cause: smartAccountContract });
      |                                      ^
  888 |                     });
  889 |                 }
  890 |               },
Call Stack
  smartAccountContract.addColl._catch$argument_0 (packages/mobile/components/CollateralManagementModal.tsx:887:38)

When I got redirected to MM a second time and I try to go back to the app I get this error as well

 ERROR  [Error: Unable to open URL: metamask://wc?requestId=1761685740468841&sessionTopic=4512a91a31cf6b93e07ff30be2daac33bf8bda4c168f991a4d98164078a929d3] Error: Unable to open URL: metamask://wc?requestId=1761685740468841&sessionTopic=4512a91a31cf6b93e07ff30be2daac33bf8bda4c168f991a4d98164078a929d3

AppKit SDK version

2.0.1

Output of npx react-native info

System:
  OS: macOS 15.3.2
  CPU: (8) arm64 Apple M2
  Memory: 352.33 MB / 16.00 GB
  Shell:
    version: 3.2.57
    path: /bin/bash
Binaries:
  Node:
    version: 20.13.1
    path: /private/var/folders/77/xk_dk18j35d3qlpn53s8z7dw0000gn/T/xfs-ca2a2422/node
  Yarn:
    version: 3.5.1
    path: /private/var/folders/77/xk_dk18j35d3qlpn53s8z7dw0000gn/T/xfs-ca2a2422/yarn
  npm:
    version: 10.5.2
    path: /Users/christophgriehl/.nvm/versions/node/v20.13.1/bin/npm
  Watchman:
    version: 2025.08.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.5
      - iOS 18.5
      - macOS 15.5
      - tvOS 18.5
      - visionOS 2.5
      - watchOS 11.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2513.14007798
  Xcode:
    version: 16.4/16F6
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.16
    path: /usr/bin/javac
  Ruby:
    version: 3.4.5
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.2
    wanted: ^20.0.2
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.5
    wanted: 0.81.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Expo Version (if applies)

54.0.20

Steps to reproduce

See video. Maybe the logs and my init code helps.

Snack, code example, screenshot, or link to a repository

import AsyncStorage from "@react-native-async-storage/async-storage";
import { EthersAdapter,  } from "@reown/appkit-ethers-react-native";
import { createAppKit, type AppKitNetwork, AppKitProvider, AppKit } from "@reown/appkit-react-native";
import { sei } from "viem/chains";
import { MMKV } from 'react-native-mmkv';
import { safeJsonParse, safeJsonStringify } from '@walletconnect/safe-json';
import type { Storage } from '@reown/appkit-react-native';

// 1. Get projectId from https://dashboard.reown.com
const projectId = "xxx";
// 2. Create config
const metadata = {
  name: 'Apollon',
  description: 'AppKit for Apollon',
  url: 'https://app.apollon.fi', // origin must match your domain & subdomain
  icons: ['https://app.apollon.fi/assets/svgs/Apollon_logo_negative.svg'],
  redirect: {
    native: "apollon://",
    universal: "YOUR_APP_UNIVERSAL_LINK.com",
  },
};

// 3. Define your chains
const seiMainnet = {
  id: 1329,
  name: 'Sei Network',
  nativeCurrency: { name: 'Sei', symbol: 'SEI', decimals: 18 },
  rpcUrls: {
    default: {
      http: ['https://evm-rpc.sei-apis.com/'],
      webSocket: ['wss://evm-ws.sei-apis.com/'],
    },
  },
  blockExplorers: {
    default: {
      name: 'Seitrace',
      url: 'https://seitrace.com',
      apiUrl: 'https://seitrace.com/pacific-1/api',
    },
  },
  contracts: {
    multicall3: {
      address: '0xcA11bde05977b3631167028862bE2a173976CA11',
    },
  },
  chainNamespace: 'eip155' as any,
  caipNetworkId: "eip155:1329" as '`${string}:${string}`',
  testnet: false
};


const mmkv = new MMKV();

const storage: Storage = {
    getKeys: async () => {
      return mmkv.getAllKeys();
    },
    getEntries: async <T = any>(): Promise<[string, T][]> => {
      function parseEntry(key: string): [string, any] {
        const value = mmkv.getString(key);
        return [key, safeJsonParse(value ?? '')];
      }

      const keys = mmkv.getAllKeys();
      return keys.map(parseEntry);
    },
    setItem: async <T = any>(key: string, value: T) => {
      return mmkv.set(key, safeJsonStringify(value));
    },
    getItem: async <T = any>(key: string): Promise<T | undefined> => {
      const item = mmkv.getString(key);
      if (typeof item === 'undefined' || item === null) {
        return undefined;
      }

      return safeJsonParse(item) as T;
    },
    removeItem: async (key: string) => {
      return mmkv.delete(key);
    },
  };


// const appNetworks: AppKitNetwork[] = [sei];

// 1. Define your AppKitNetworks (for AppKit's UI and network management)
// These can come from viem/chains (for EVM) or be custom AppKitNetwork objects.
const appNetworks: AppKitNetwork[] = [
  seiMainnet
];

const ethersAdapter = new EthersAdapter();

// 4. Create modal
export const appKit = createAppKit({
  projectId,
  metadata,
  networks: appNetworks, // Master list of networks for AppKit UI and context
  defaultNetwork: seiMainnet,

  adapters: [
    ethersAdapter,  // Handles EVM chains defined in 'networks'
  ],
  storage,
  themeMode: 'dark',
  debug: true
});


export function WalletConnectProvider({ children }: { children: React.ReactNode }) {
  return  <AppKitProvider instance={appKit}>
    <AppKit />
    {children}
  </AppKitProvider>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions