Web3Modal
Supported Versions: >=v2 Support Date: 2023.10.18
Development Example
js
import { createWeb3Modal } from "@web3modal/wagmi/react";
import { http, createConfig, WagmiProvider } from "wagmi";
import { mainnet, arbitrum } from "viem/chains";
import { walletConnect, coinbaseWallet } from "wagmi/connectors";
// 1. Get projectId at https://cloud.walletconnect.com
const projectId = 'YOUR_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"],
};
// Define chains
const chains = [mainnet, arbitrum] as const
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 });
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<WagmiProvider config={wagmiConfig}>
<w3m-button />
</WagmiProvider>
</React.StrictMode>
);
import { createWeb3Modal } from "@web3modal/wagmi/react";
import { http, createConfig, WagmiProvider } from "wagmi";
import { mainnet, arbitrum } from "viem/chains";
import { walletConnect, coinbaseWallet } from "wagmi/connectors";
// 1. Get projectId at https://cloud.walletconnect.com
const projectId = 'YOUR_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"],
};
// Define chains
const chains = [mainnet, arbitrum] as const
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 });
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<WagmiProvider config={wagmiConfig}>
<w3m-button />
</WagmiProvider>
</React.StrictMode>
);