You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a console log in the provider-jsonrpc.ts file
JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)
and here's how I try removing it (AT THE VERY BOTTOM OF THE CODE ALMOST )
upd ( SKIP THE CODE ) it's redundant and irrelevant, you know what console.log I'm talking about
import{JsonRpcApiProviderOptions,JsonRpcError,JsonRpcPayload,JsonRpcProvider,JsonRpcResult,Network,Networkish,Wallet,assertArgument,makeError,}from'ethers';typePayload={payload: JsonRpcPayload; resolve: ResolveFunc; reject: RejectFunc};typeResolveFunc=(result: JsonRpcResult)=>void;typeRejectFunc=(error: Error)=>void;typeTimer=ReturnType<typeofsetTimeout>;functionstall(duration: number): Promise<void>{returnnewPromise((resolve)=>{setTimeout(resolve,duration);});}constdefaultOptions={polling: false,staticNetwork: null,batchStallTime: 10,// 10msbatchMaxSize: 1<<20,// 1MbbatchMaxCount: 100,// 100 requestscacheTimeout: 250,pollingInterval: 4000,};exportclassRetriableJsonRpcProviderextendsJsonRpcProvider{
#options: Required<JsonRpcApiProviderOptions>;
#scheduleDrain(): void{if(this.#drainTimer){return;}// If we aren't using batching, no harm in sending it immediatelyconststallTime=this._getOption('batchMaxCount')===1 ? 0 : this._getOption('batchStallTime');this.#drainTimer=setTimeout(()=>{this.#drainTimer=null;constpayloads=this.#payloads;this.#payloads=[];while(payloads.length){// Create payload batches that satisfy our batch constraintsconstbatch=[<Payload>payloads.shift()];
while (payloads.length) {if(batch.length===this.#options.batchMaxCount){break;}
batch.push(<Payload>payloads.shift());
const bytes = JSON.stringify(batch.map((p) =>p.payload));if(bytes.length>this.#options.batchMaxSize){payloads.unshift(<Payload>batch.pop());
break;
}}
// Process the result to each payload
(async () =>{constpayload=batch.length===1 ? batch[0].payload : batch.map((p)=>p.payload);this.emit('debug',{action: 'sendRpcPayload', payload });try{constresult=awaitthis._send(payload);this.emit('debug',{action: 'receiveRpcResult', result });// Process results in batch orderfor(const{ resolve, reject, payload }ofbatch){if(this.destroyed){reject(makeError('provider destroyed; cancelled request','UNSUPPORTED_OPERATION',{operation: payload.method}));continue;}// Find the matching resultconst resp =result.filter((r)=>r.id===payload.id)[0];// No result; the node failed us in unexpected waysif(resp==null){consterror=makeError('missing response for request','BAD_DATA',{value: result,info: { payload },});this.emit('error',error);reject(error);continue;}// The response is an errorif('error'inresp){reject(this.getRpcError(payload,respasJsonRpcError));continue;}
// All good; send the result
resolve(resp.result);
}}catch(error: any){this.emit('debug',{action: 'receiveRpcError', error });for(const{ reject }ofbatch){// @TODO: augment the error with the payloadreject(error);}}})();}},stallTime);}
#notReady: null|{promise: Promise<void>;resolve: null|((v: void)=>void);};
#network: null | Network;
#payloads: Array<Payload>;
#drainTimer: null | Timer;
#nextId: number;
#pendingDetectNetwork: null | Promise<Network>;
providerList: JsonRpcProvider[];
currentIndex = 0;
error: any;
acc: any;
signer: any;
constructor(rpcs: string[], acc: any, network?: Networkish, options?: JsonRpcApiProviderOptions) {super(rpcs[0],network,options);this.#nextId=1;this.#options=Object.assign({},defaultOptions,options||{});this.#payloads=[];this.#drainTimer=null;this.#network=null;this.#pendingDetectNetwork=null;{letresolve: null|((value: void)=>void)=null;constpromise=newPromise((_resolve: (value: void)=>void)=>{
resolve =_resolve;});this.#notReady={ promise, resolve };}conststaticNetwork=this._getOption('staticNetwork');if(typeofstaticNetwork==='boolean'){assertArgument(!staticNetwork||network!=='any',"staticNetwork cannot be used on special network 'any'",'options',options);if(staticNetwork&&network!=null){this.#network=Network.from(network);}}elseif(staticNetwork){// Make sure any static network is compatbile with the provided netwrokassertArgument(network==null||staticNetwork.matches(network),'staticNetwork MUST match network object','options',options);this.#network=staticNetwork;}this.providerList=rpcs.map((url)=>newJsonRpcProvider(url));this.acc=acc;constprovider=this.selectProvider();this.signer=newWallet(this.acc.pk,provider);}asyncsend(method: string,params: Array<any>|Record<string,any>): Promise<any>{
this._start();try{// select properly providerconstprovider=this.selectProvider();this.signer=newWallet(this.acc.pk,provider);// send rpc callreturnawaitprovider.send(method,params);}catch(error){console.log('Switching to the next rpc url....\n');awaitnewPromise((r)=>setTimeout(r,1*1000));returnthis.send(method,params);}}privateselectProvider(){this.currentIndex=this.providerList.length===1 ? 0 : (this.currentIndex+1)%this.providerList.length;// select current providerconstprovider=this.providerList[this.currentIndex];returnprovider;}// Override _start() method to customize it_start(): void{if(this.#notReady==null||this.#notReady.resolve==null){return;}
this.#notReady.resolve();
this.#notReady = null;
(async () =>{// Bootstrap the networkwhile(this.#network==null&&!this.destroyed){try{this.#network=awaitthis._detectNetwork();} catch (error) {if(this.destroyed){break;}
// Removed the console log statement from here
this.emit(
'error',
makeError('failed to bootstrap network detection', 'NETWORK_ERROR', {event: 'initial-network-discovery',info: { error }})
);
await stall(1000);
}}// Start dispatching requeststhis.#scheduleDrain();})();}}
but I still get this console log.......why?? how to make it go away ( of course editing the lib file itself is not an option )
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
There is a console log in the provider-jsonrpc.ts file
JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)
and here's how I try removing it (AT THE VERY BOTTOM OF THE CODE ALMOST )
upd ( SKIP THE CODE ) it's redundant and irrelevant, you know what console.log I'm talking about
but I still get this console log.......why?? how to make it go away ( of course editing the lib file itself is not an option )
Beta Was this translation helpful? Give feedback.
All reactions