update web3modal example (#339)

This commit is contained in:
Glitch 2023-12-07 03:55:17 -03:00 committed by GitHub
parent de1cb08471
commit 6566c39391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5151 additions and 3728 deletions

View File

@ -10,12 +10,11 @@
"preview": "vite preview"
},
"dependencies": {
"@web3modal/ethereum": "^2.7.1",
"@web3modal/react": "^2.7.1",
"@web3modal/wagmi": "^3.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "^1.4.1",
"wagmi": "^1.3.9"
"viem": "^1.19.11",
"wagmi": "^1.4.8"
},
"devDependencies": {
"@types/react": "^18.2.14",

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +1,32 @@
import React from "react";
import ReactDOM from "react-dom/client";
import {
EthereumClient,
w3mConnectors,
w3mProvider,
} from "@web3modal/ethereum";
import { Web3Modal, Web3Button } from "@web3modal/react";
import { configureChains, createConfig, WagmiConfig } from "wagmi";
import { arbitrum, mainnet, polygon } from "wagmi/chains";
import React from "react"
import ReactDOM from "react-dom/client"
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/react'
// 1. select chains
const chains = [arbitrum, mainnet, polygon];
const projectId = import.meta.env.VITE_PROJECT_ID;
import { WagmiConfig } from 'wagmi'
import { arbitrum, mainnet } from 'viem/chains'
// 2. generate wagmiConfig with w3mConnectors
const { publicClient } = configureChains(chains, [w3mProvider({ projectId })]);
const wagmiConfig = createConfig({
autoConnect: true,
connectors: w3mConnectors({ projectId, chains }),
publicClient,
});
// 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")
// 3. create ethereumClient
const ethereumClient = new EthereumClient(wagmiConfig, chains);
// 2. Create wagmiConfig
const metadata = {
name: 'Web3Modal',
description: 'Web3Modal Example',
url: 'https://web3modal.com',
icons: ['https://avatars.githubusercontent.com/u/37784886']
}
const chains = [mainnet, arbitrum]
const wagmiConfig = defaultWagmiConfig({ chains, projectId, metadata })
// 3. Create modal
createWeb3Modal({ wagmiConfig, projectId, chains })
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<WagmiConfig config={wagmiConfig}>
<Web3Button />
<w3m-button/>
</WagmiConfig>
<Web3Modal projectId={projectId} ethereumClient={ethereumClient} />
</React.StrictMode>
);
)

File diff suppressed because it is too large Load Diff