Skip to content

Commit c701c38

Browse files
hsynlmsMananTank
andauthored
feat: ethers skipFetchSetup support (#2085)
Co-authored-by: Manan Tank <[email protected]>
1 parent 328ef5d commit c701c38

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.changeset/great-experts-chew.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@thirdweb-dev/sdk": patch
3+
---
4+
5+
Fix error when fetching data on `vite-node` environment by setting a global variable `TW_SKIP_FETCH_SETUP` to `true`. Fixes https://github.com/thirdweb-dev/js/issues/2002
6+
7+
Setting this flag sets `skipFetchSetup` to `true` in [ethers ConnectionInfo](https://docs.ethers.org/v5/api/utils/web/#ConnectionInfo)
8+
9+
```ts
10+
// set this global variable
11+
globalThis.TW_SKIP_FETCH_SETUP = true;
12+
13+
// use the thirdweb sdk...
14+
```

packages/sdk/src/evm/constants/urls.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ export function getProviderFromRpcUrl(
284284
if (existingProvider) {
285285
return existingProvider;
286286
}
287+
288+
// TODO: remove below `skipFetchSetup` logic when ethers.js v6 support arrives
289+
let _skipFetchSetup = false;
290+
if (
291+
typeof globalThis !== "undefined" &&
292+
"TW_SKIP_FETCH_SETUP" in globalThis &&
293+
typeof (globalThis as any).TW_SKIP_FETCH_SETUP === "boolean"
294+
) {
295+
_skipFetchSetup = (globalThis as any).TW_SKIP_FETCH_SETUP as boolean;
296+
}
287297

288298
// Otherwise, create a new provider on the specific network
289299
const newProvider = chainId
@@ -292,13 +302,15 @@ export function getProviderFromRpcUrl(
292302
{
293303
url: rpcUrl,
294304
headers,
305+
skipFetchSetup: _skipFetchSetup,
295306
},
296307
chainId,
297308
)
298309
: // Otherwise fall back to the built in json rpc batch provider
299310
new providers.JsonRpcBatchProvider({
300311
url: rpcUrl,
301312
headers,
313+
skipFetchSetup: _skipFetchSetup,
302314
});
303315

304316
// Save the provider in our cache

0 commit comments

Comments
 (0)