@@ -15,7 +15,7 @@ import * as fs from "fs";
1515import * as path from "path" ;
1616import { createWalletClient , http , parseEther } from "viem" ;
1717import { privateKeyToAccount } from "viem/accounts" ;
18- import { baseSepolia } from "viem/chains" ;
18+ import { baseSepolia , base } from "viem/chains" ;
1919import {
2020 createBicoBundlerClient ,
2121 toNexusAccount ,
@@ -88,6 +88,18 @@ async function testWithBiconomySDK() {
8888 console . log ( " ✅ Viem client configured\n" ) ;
8989 console . log ( "=" . repeat ( 80 ) ) ;
9090
91+ // ============================================================================
92+ // DETECT NETWORK
93+ // ============================================================================
94+
95+ const network = await ethers . provider . getNetwork ( ) ;
96+ const isMainnet = network . chainId === 8453 ; // Base Mainnet
97+ const viemChain = isMainnet ? base : baseSepolia ;
98+
99+ console . log ( `\n🌐 Network: ${ viemChain . name } (chainId: ${ network . chainId } )` ) ;
100+ console . log ( ` Mode: ${ isMainnet ? 'MAINNET 🔴' : 'TESTNET 🟡' } \n` ) ;
101+ console . log ( "=" . repeat ( 80 ) ) ;
102+
91103 // ============================================================================
92104 // CREATE NEXUS ACCOUNT WITH BICONOMY SDK
93105 // ============================================================================
@@ -106,7 +118,7 @@ async function testWithBiconomySDK() {
106118 const nexusAccount = await toNexusAccount ( {
107119 signer : eoaAccount ,
108120 chainConfiguration : {
109- chain : baseSepolia ,
121+ chain : viemChain ,
110122 transport : http ( ) ,
111123 version : versionConfig ,
112124 } ,
@@ -152,8 +164,14 @@ async function testWithBiconomySDK() {
152164
153165 console . log ( "\n🌐 Creating Bundler Client..." ) ;
154166
155- // Load bundler URL from deployment or environment
156- const bundlerUrl = process . env . NEXUS_BUNDLER_URL || "https://bundler.biconomy.io/api/v2/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44" ;
167+ // Load bundler URL based on network
168+ const bundlerUrl = isMainnet
169+ ? ( process . env . BICONOMY_BUNDLER_URL_BASE || process . env . NEXUS_BUNDLER_URL )
170+ : ( process . env . NEXUS_BUNDLER_URL || "https://bundler.biconomy.io/api/v2/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44" ) ;
171+
172+ if ( ! bundlerUrl ) {
173+ throw new Error ( "Bundler URL not configured! Set BICONOMY_BUNDLER_URL_BASE in .env" ) ;
174+ }
157175
158176 console . log ( ` Bundler URL: ${ bundlerUrl } \n` ) ;
159177
0 commit comments