-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Web3Modal + Wagmi v2 example in React (#422)
- Loading branch information
1 parent
89a3d60
commit a2f89d0
Showing
3 changed files
with
5,278 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom/client" | ||
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react' | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import { createWeb3Modal } from "@web3modal/wagmi/react"; | ||
|
||
import { WagmiConfig } from 'wagmi' | ||
import { arbitrum, mainnet } from 'viem/chains' | ||
import { http, createConfig, WagmiProvider } from "wagmi"; | ||
import { mainnet, arbitrum } from "viem/chains"; | ||
import { walletConnect, coinbaseWallet } from "wagmi/connectors"; | ||
|
||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
|
||
// 0. Setup queryClient | ||
const queryClient = new QueryClient(); | ||
|
||
// 1. Get projectId at https://cloud.walletconnect.com | ||
const projectId = import.meta.env.VITE_PROJECT_ID | ||
if(!projectId) throw new Error("Project ID is undefined") | ||
const projectId = import.meta.env.VITE_PROJECT_ID; | ||
if (!projectId) throw new Error("Project ID is undefined"); | ||
|
||
// 2. Create wagmiConfig | ||
const metadata = { | ||
name: 'Web3Modal', | ||
description: 'Web3Modal Example', | ||
url: 'https://web3modal.com', | ||
icons: ['https://avatars.githubusercontent.com/u/37784886'] | ||
} | ||
name: "Web3Modal", | ||
description: "Web3Modal Example", | ||
url: "https://web3modal.com", | ||
icons: ["https://avatars.githubusercontent.com/u/37784886"], | ||
}; | ||
|
||
// Define chains | ||
const chains = [mainnet, arbitrum]; | ||
|
||
const chains = [mainnet, arbitrum] | ||
const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata }) | ||
const wagmiConfig = createConfig({ | ||
chains, // Use the defined chains here | ||
transports: { | ||
[mainnet.id]: http(), | ||
[arbitrum.id]: http(), | ||
}, | ||
connectors: [ | ||
walletConnect({ projectId, metadata, showQrModal: false }), | ||
coinbaseWallet({ | ||
appName: metadata.name, | ||
appLogoUrl: metadata.icons[0], | ||
}), | ||
], | ||
}); | ||
|
||
// 3. Create modal | ||
createWeb3Modal({ wagmiConfig, projectId, chains }) | ||
createWeb3Modal({ wagmiConfig, projectId, chains }); | ||
|
||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( | ||
<React.StrictMode> | ||
<WagmiConfig config={wagmiConfig}> | ||
<w3m-button/> | ||
</WagmiConfig> | ||
<WagmiProvider config={wagmiConfig}> | ||
<QueryClientProvider client={queryClient}> | ||
<w3m-button /> | ||
</QueryClientProvider> | ||
</WagmiProvider> | ||
</React.StrictMode> | ||
) | ||
); |
Oops, something went wrong.