Skip to content

Commit 8233b77

Browse files
committed
feat(sdk/eip1193): add switch chain handler
1 parent d16fb21 commit 8233b77

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Account, Wallet } from "../../wallets/interfaces/wallet.js";
99
import { createWalletEmitter } from "../../wallets/wallet-emitter.js";
1010
import type { WalletId } from "../../wallets/wallet-types.js";
1111
import type { EIP1193Provider } from "./types.js";
12+
import * as ox__Hex from "ox/Hex";
1213

1314
export type FromEip1193AdapterOptions = {
1415
provider: EIP1193Provider | (() => Promise<EIP1193Provider>);
@@ -54,7 +55,7 @@ export function fromProvider(options: FromEip1193AdapterOptions): Wallet {
5455
chain = undefined;
5556
}
5657

57-
let handleDisconnect = async () => {};
58+
let handleDisconnect = async () => { };
5859

5960
const unsubscribeDisconnect = emitter.subscribe("disconnect", () => {
6061
reset();
@@ -66,8 +67,11 @@ export function fromProvider(options: FromEip1193AdapterOptions): Wallet {
6667
account = _account;
6768
});
6869

69-
let handleSwitchChain: (chain: Chain) => Promise<void> = async () => {
70-
throw new Error("Not implemented");
70+
let handleSwitchChain: (c: Chain) => Promise<void> = async (c) => {
71+
await provider?.request({
72+
method: "wallet_switchEthereumChain",
73+
params: [{ chainId: ox__Hex.fromNumber(c.id) }],
74+
});
7175
};
7276

7377
return {

0 commit comments

Comments
 (0)