@@ -78,6 +78,14 @@ const createSuccessResponse = (data: any): MessageResponse => {
7878 } ;
7979} ;
8080
81+ // Helper function to parse chainId from string to number
82+ const parseChainId = ( chainId : string ) : number => {
83+ // Handle both hex (0x...) and decimal string formats
84+ return chainId . startsWith ( '0x' )
85+ ? parseInt ( chainId , 16 )
86+ : parseInt ( chainId , 10 ) ;
87+ } ;
88+
8189// Helper function to create error response
8290const createErrorResponse = ( error : string , code ?: number ) : MessageResponse => {
8391 return {
@@ -104,7 +112,7 @@ export const evmRpcHandler = {
104112 // Convert chainId to number if it's a string
105113 let targetChainId : number ;
106114 if ( typeof chainId === 'string' ) {
107- targetChainId = parseInt ( chainId , 10 ) ;
115+ targetChainId = parseChainId ( chainId ) ;
108116 if ( isNaN ( targetChainId ) ) {
109117 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
110118 }
@@ -144,7 +152,7 @@ export const evmRpcHandler = {
144152 // Convert chainId to number if it's a string
145153 let targetChainId : number ;
146154 if ( typeof chainId === 'string' ) {
147- targetChainId = parseInt ( chainId , 10 ) ;
155+ targetChainId = parseChainId ( chainId ) ;
148156 if ( isNaN ( targetChainId ) ) {
149157 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
150158 }
@@ -177,7 +185,7 @@ export const evmRpcHandler = {
177185 // Convert chainId to number if it's a string
178186 let targetChainId : number ;
179187 if ( typeof chainId === 'string' ) {
180- targetChainId = parseInt ( chainId , 10 ) ;
188+ targetChainId = parseChainId ( chainId ) ;
181189 if ( isNaN ( targetChainId ) ) {
182190 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
183191 }
@@ -219,7 +227,10 @@ export const evmRpcHandler = {
219227 // Convert chainId to number if it's a string
220228 let targetChainId : number ;
221229 if ( typeof chainId === 'string' ) {
222- targetChainId = parseInt ( chainId , 10 ) ;
230+ // Handle both hex (0x...) and decimal string formats
231+ targetChainId = chainId . startsWith ( '0x' )
232+ ? parseInt ( chainId , 16 )
233+ : parseChainId ( chainId ) ;
223234 if ( isNaN ( targetChainId ) ) {
224235 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
225236 }
@@ -252,7 +263,10 @@ export const evmRpcHandler = {
252263 // Convert chainId to number if it's a string
253264 let targetChainId : number ;
254265 if ( typeof chainId === 'string' ) {
255- targetChainId = parseInt ( chainId , 10 ) ;
266+ // Handle both hex (0x...) and decimal string formats
267+ targetChainId = chainId . startsWith ( '0x' )
268+ ? parseInt ( chainId , 16 )
269+ : parseChainId ( chainId ) ;
256270 if ( isNaN ( targetChainId ) ) {
257271 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
258272 }
@@ -287,7 +301,7 @@ export const evmRpcHandler = {
287301 // Convert chainId to number if it's a string
288302 let targetChainId : number ;
289303 if ( typeof chainId === 'string' ) {
290- targetChainId = parseInt ( chainId , 10 ) ;
304+ targetChainId = parseChainId ( chainId ) ;
291305 if ( isNaN ( targetChainId ) ) {
292306 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
293307 }
@@ -326,7 +340,7 @@ export const evmRpcHandler = {
326340 // Convert chainId to number if it's a string
327341 let targetChainId : number ;
328342 if ( typeof chainId === 'string' ) {
329- targetChainId = parseInt ( chainId , 10 ) ;
343+ targetChainId = parseChainId ( chainId ) ;
330344 if ( isNaN ( targetChainId ) ) {
331345 return createErrorResponse ( `Invalid chainId: ${ chainId } ` , 4001 ) ;
332346 }
0 commit comments