|
2 | 2 | "thirdweb": minor |
3 | 3 | --- |
4 | 4 |
|
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 | +``` |
0 commit comments