@@ -129,16 +129,32 @@ async function callReadOnly(opts: {
129129 functionArgs : ClarityValue [ ] ;
130130 senderAddress : string ;
131131} ) : Promise < unknown > {
132- const cv = await fetchCallReadOnlyFunction ( {
133- contractAddress : opts . contractAddress ,
134- contractName : opts . contractName ,
135- functionName : opts . functionName ,
136- functionArgs : opts . functionArgs ,
137- network : STACKS_NETWORK_OBJ ,
138- client : { baseUrl : STACKS_API_BASE } ,
139- senderAddress : opts . senderAddress ,
140- } ) ;
141- return unwrapCvToValue ( cvToValue ( cv ) as unknown ) ;
132+ const tries = 3 ;
133+ for ( let attempt = 1 ; attempt <= tries ; attempt += 1 ) {
134+ try {
135+ const cv = await fetchCallReadOnlyFunction ( {
136+ contractAddress : opts . contractAddress ,
137+ contractName : opts . contractName ,
138+ functionName : opts . functionName ,
139+ functionArgs : opts . functionArgs ,
140+ network : STACKS_NETWORK_OBJ ,
141+ client : { baseUrl : STACKS_API_BASE } ,
142+ senderAddress : opts . senderAddress ,
143+ } ) ;
144+ return unwrapCvToValue ( cvToValue ( cv ) as unknown ) ;
145+ } catch ( err ) {
146+ const message =
147+ err instanceof Error ? err . message : typeof err === "string" ? err : "" ;
148+ const looksRateLimited =
149+ message . includes ( "429" ) ||
150+ message . toLowerCase ( ) . includes ( "too many requests" ) ;
151+
152+ if ( ! looksRateLimited || attempt >= tries ) throw err ;
153+ await sleep ( 250 * attempt ) ;
154+ }
155+ }
156+
157+ return null ;
142158}
143159
144160async function getContractOwner ( ) : Promise < string | null > {
0 commit comments