1- import { NetworkName , RPC_NODES , SupportedRpcVersion } from '../global/constants' ;
1+ import { NetworkName , RPC_DEFAULT_NODES , SupportedRpcVersion } from '../global/constants' ;
22import {
33 BlockIdentifier ,
44 BlockTag ,
@@ -24,6 +24,7 @@ import { compressProgram } from './stark';
2424import type { GetTransactionReceiptResponse } from './transactionReceipt/transactionReceipt.type' ;
2525import { logger } from '../global/logger' ;
2626import { ETransactionVersion } from '../provider/types/spec.type' ;
27+ import { config } from '../global/config' ;
2728
2829/**
2930 * Helper - Async Sleep for 'delay' time
@@ -120,15 +121,39 @@ export function parseContract(contract: CompiledContract | string): ContractClas
120121 * // result = "https://starknet-mainnet.public.blastapi.io/rpc/v0_7"
121122 * ```
122123 */
123- export const getDefaultNodeUrl = ( networkName ?: NetworkName , mute : boolean = false ) : string => {
124+ export const getDefaultNodeUrl = (
125+ networkName ?: NetworkName ,
126+ mute : boolean = false ,
127+ rpcVersion ?: SupportedRpcVersion
128+ ) : string => {
124129 if ( ! mute ) {
125130 logger . info ( 'Using default public node url, please provide nodeUrl in provider options!' ) ;
126131 }
127- const nodes = RPC_NODES [ networkName ?? NetworkName . SN_SEPOLIA ] ;
132+ const rpcNodes = getDefaultNodes ( rpcVersion ?? config . get ( 'rpcVersion' ) ) ;
133+
134+ const nodes = rpcNodes [ networkName ?? NetworkName . SN_SEPOLIA ] ;
128135 const randIdx = Math . floor ( Math . random ( ) * nodes . length ) ;
129136 return nodes [ randIdx ] ;
130137} ;
131138
139+ /**
140+ * return Defaults RPC Nodes endpoints
141+ */
142+ export function getDefaultNodes ( rpcVersion : SupportedRpcVersion ) {
143+ const vToUrl = ( versionString : SupportedRpcVersion ) =>
144+ `v${ versionString . replace ( / ^ v / , '' ) . replace ( / \. / g, '_' ) } ` ;
145+
146+ const nodes : any = { ...RPC_DEFAULT_NODES } ;
147+
148+ Object . keys ( nodes ) . forEach ( function ( key , _ ) {
149+ nodes [ key ] = nodes [ key ] . map ( ( it : any ) => {
150+ return `${ it } ${ vToUrl ( rpcVersion ) } ` ;
151+ } ) ;
152+ } ) ;
153+
154+ return nodes ;
155+ }
156+
132157export const validBlockTags = Object . values ( BlockTag ) ;
133158
134159/**
0 commit comments