You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then in your application, you can use the connector to trigger the in-app wallet connection.
66
+
### Using the ConnectButton or ConnectEmbed with a wagmi application
67
+
68
+
You can use the thirdweb react connection components and hooks like ConnectButton, ConnectEmbed, useConnectModal, etc, but still keep using wagmi for the rest of the application.
69
+
70
+
To do so, you will need to connect the `inAppWalletConnector` connector from the `@thirdweb-dev/wagmi-adapter` package with the connected thirdweb wallet.
71
+
72
+
You can do this at any time after connecting the thirdweb wallet, a convenient place to do this is in the `onConnect` callback of the ConnectButton or ConnectEmbed.
73
+
74
+
```tsx
75
+
const { connectors, connect } =useConnect(); // from wagmi
76
+
77
+
<ConnectButton
78
+
client={client}
79
+
onConnect={(wallet) => {
80
+
// connect the wagmi connector with the connected thirdweb wallet
81
+
const twConnector =connectors.find(
82
+
(c) =>c.id==="in-app-wallet",
83
+
);
84
+
if (twConnector) {
85
+
const options = {
86
+
wallet, // pass the connected wallet
87
+
} satisfiesConnectionOptions; // for type safety
88
+
connect({
89
+
connector: twConnector,
90
+
chainId: chain.id,
91
+
...options,
92
+
});
93
+
}
94
+
}}
95
+
/>
96
+
```
97
+
98
+
Make sure your app is wrapped in a `<ThirdwebProvider>` as well as a `<WagmiProvider>` since both contexts will be used here. From there, the wallet state will be in sync between the 2 libraries.
99
+
100
+
**Note:** the ConnectButton and ConnectEmbed handle reconnecting automatically on page reload. If not using those components (ie. useConnectModal or useConnect hooks directly), you will need to handle reconnecting by explicitely calling `useAutoConnect()`, and doing the same wagmi connection from the `onConnect` callback.
101
+
102
+
### Using the connector directly (headless mode)
103
+
104
+
You can also use the `inAppWalletConnector` connector directly in your application to connect to the thirdweb wallet without needing a `<ThirdwebProvider>` at all.
67
105
68
106
```ts
69
-
const { connect, connectors } =useConnect();
107
+
const { connect, connectors } =useConnect();// from wagmi
70
108
71
109
const onClick = () => {
72
110
// grab the connector
@@ -79,9 +117,10 @@ const onClick = () => {
79
117
};
80
118
```
81
119
120
+
82
121
### Converting a wagmi wallet client to a thirdweb wallet
83
122
84
-
You can use the thirdweb SDK within a wagmi application by setting the wagmi connected account as the thirdweb 'active wallet'. After that, you can use all of the react components and hooks normally, including `BuyWidget`, `TransactionButton`, etc.
123
+
You can also use the thirdweb SDK within a wagmi application by setting the wagmi connected account as the thirdweb 'active wallet'. After that, you can use all of the react components and hooks normally, including `BuyWidget`, `TransactionButton`, etc.
85
124
86
125
```ts
87
126
// Assumes you've wrapped your application in a `<ThirdwebProvider>`
0 commit comments