Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Update page.mdx (#399)
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquim Verges <[email protected]>
  • Loading branch information
joaquim-verges authored May 11, 2024
1 parent b1cd5ac commit 04e8956
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/app/typescript/v5/adapters/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,52 @@

The thirdweb SDK can work side by side with:

- wagmi
- ethers.js v5
- ethers.js v6
- viem
- older versions of the @thirdweb-dev/sdk (using the ethers.js v5 adapter)

Adapters allow you to use contracts, providers and wallets from these libraries with the thirdweb SDK and vice versa.

## Wagmi

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 `PayEmbed`, `TransactionButton`, etc.

```ts
// Assumes you've wrapped your application in a `<ThirdwebProvider>`
const { data: walletClient } = useWalletClient(); // from wagmi
const { disconnectAsync } = useDisconnect(); // from wagmi
const { switchChainAsync } = useSwitchChain(); // from wagmi
const setActiveWallet = useSetActiveWallet(); // from thirdweb/react
useEffect(() => {
const setActive = async () => {
if (walletClient) {
// adapt the walletClient to a thirdweb account
const adaptedAccount = viemAdapter.walletClient.fromViem({
walletClient: walletClient as any, // accounts for wagmi/viem version mismatches
});
// create the thirdweb wallet with the adapted account
const thirdwebWallet = createWalletAdapter({
client,
adaptedAccount,
chain: defineChain(await walletClient.getChainId()),
onDisconnect: async () => {
await disconnectAsync();
},
switchChain: async (chain) => {
await switchChainAsync({ chainId: chain.id as any });
},
});
setActiveWallet(thirdwebWallet);
}
};
setActive();
}, [walletClient]);
```

You can view a fully functioning wagmi + thirdweb app in this [github repository](https://github.com/thirdweb-example/wagmi-thirdweb-pay).

## Ethers v6

You can use an existing ethers.js v6 Signer with the thirdweb SDK by converting it using the `ethers6Adapter`:
Expand Down

0 comments on commit 04e8956

Please sign in to comment.