Skip to content

Commit 1e8ddcb

Browse files
authored
[SDK] Fix: Undefined chain ID on eip1193 provider input (#5871)
1 parent a3f59e5 commit 1e8ddcb

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

.changeset/yellow-experts-sparkle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
SDK: Gracefully ignore chain with no chain ID in `fromEip1193Provider`

packages/thirdweb/src/adapters/eip1193/from-eip1193.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ describe("fromProvider", () => {
115115
expect(chain).toBe(ANVIL_CHAIN);
116116
});
117117

118+
test("should handle connection with no chainId", async () => {
119+
const wallet = fromProvider({
120+
provider: {
121+
...mockProvider,
122+
request: () => Promise.resolve([mockAccount.address]),
123+
},
124+
});
125+
126+
await wallet.connect({
127+
client: TEST_CLIENT,
128+
chain: {
129+
...ANVIL_CHAIN,
130+
id: undefined,
131+
// biome-ignore lint/suspicious/noExplicitAny: Testing unexpected input data
132+
} as any,
133+
});
134+
});
135+
118136
test("should reset state on disconnect", async () => {
119137
const wallet = fromProvider({
120138
provider: {

packages/thirdweb/src/wallets/injected/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export async function connectEip1193Wallet({
8585
chain && chain.id === chainId ? chain : getCachedChain(chainId);
8686

8787
// if we want a specific chainId and it is not the same as the provider chainId, trigger switchChain
88-
if (chain && chain.id !== chainId) {
88+
// we check for undefined chain ID since some chain-specific wallets like Abstract will not send a chain ID on connection
89+
if (chain && typeof chain.id !== "undefined" && chain.id !== chainId) {
8990
await switchChain(provider, chain);
9091
connectedChain = chain;
9192
}

0 commit comments

Comments
 (0)