Skip to content

Commit 8460f6a

Browse files
committed
feat: Add comprehensive EIP1193 adapters with conversion and provider support
docs: Add code examples for EIP1193 wallet adapters
1 parent a7dc471 commit 8460f6a

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

.changeset/eleven-chicken-smile.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,46 @@
22
"thirdweb": minor
33
---
44

5-
Adds EIP1193 adapters
5+
Adds EIP1193 adapters that allow conversion between Thirdweb wallets and EIP-1193 providers:
6+
7+
- `EIP1193.fromProvider()`: Creates a Thirdweb wallet from any EIP-1193 compatible provider (like MetaMask, WalletConnect)
8+
- `EIP1193.toProvider()`: Converts a Thirdweb wallet into an EIP-1193 provider that can be used with any web3 library
9+
10+
Key features:
11+
- Full EIP-1193 compliance for seamless integration
12+
- Handles account management (connect, disconnect, chain switching)
13+
- Supports all standard Ethereum JSON-RPC methods
14+
- Comprehensive event system for state changes
15+
- Type-safe interfaces with full TypeScript support
16+
17+
Examples:
18+
19+
```ts
20+
// Convert MetaMask's provider to a Thirdweb wallet
21+
const wallet = EIP1193.fromProvider({
22+
provider: window.ethereum,
23+
walletId: "io.metamask"
24+
});
25+
26+
// Use like any other Thirdweb wallet
27+
const account = await wallet.connect({
28+
client: createThirdwebClient({ clientId: "..." })
29+
});
30+
31+
// Convert a Thirdweb wallet to an EIP-1193 provider
32+
const provider = EIP1193.toProvider({
33+
wallet,
34+
chain: ethereum,
35+
client: createThirdwebClient({ clientId: "..." })
36+
});
37+
38+
// Use with any EIP-1193 compatible library
39+
const accounts = await provider.request({
40+
method: "eth_requestAccounts"
41+
});
42+
43+
// Listen for events
44+
provider.on("accountsChanged", (accounts) => {
45+
console.log("Active accounts:", accounts);
46+
});
47+
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function fromProvider(options: FromEip1193AdapterOptions): Wallet {
8080
chain = undefined;
8181
}
8282

83-
let handleDisconnect = async () => { };
83+
let handleDisconnect = async () => {};
8484

8585
const unsubscribeDisconnect = emitter.subscribe("disconnect", () => {
8686
reset();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ export function toProvider(options: ToEip1193ProviderOptions): EIP1193Provider {
119119
const account = connectOverride
120120
? await connectOverride(wallet)
121121
: await wallet.connect({
122-
client,
123-
});
122+
client,
123+
});
124124
if (!account) {
125125
throw new Error("Unable to connect wallet");
126126
}

0 commit comments

Comments
 (0)