-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwagmi.config.ts
88 lines (73 loc) · 2.46 KB
/
wagmi.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { authConnector } from "@web3modal/wagmi";
import { createPublicClient, createWalletClient } from "viem";
import { createConfig, http } from "wagmi";
import { base, Chain, optimism, optimismSepolia } from "wagmi/chains";
import { coinbaseWallet, injected, walletConnect } from "wagmi/connectors";
declare module "wagmi" {
interface Register {
config: typeof config;
}
}
export const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;
if (!projectId) throw new Error("Project ID is not defined");
const metadata = {
name: "Web3Modal",
description: "Web3Modal Ethereum Ecosystem",
url: process.env.NEXT_PUBLIC_APP_URL ?? "http://127.0.0.1:3000", // origin must match your domain & subdomain
icons: ["https://avatars.githubusercontent.com/u/37784886"],
};
const chains: [Chain, ...Chain[]] = [optimism, base];
if (process.env.NODE_ENV === "development") {
chains.push(optimismSepolia);
}
// Used for read-only operations and for simulating contract interactions
export const publicClients = chains.map((chain) =>
createPublicClient({
chain,
transport: http(),
})
);
export const getPublicClient = (chainId: number) => {
const client = publicClients.find((client) => client.chain.id === chainId);
if (!client) throw new Error(`Unsupported chain ID: ${chainId}`);
return client;
};
// Used for write operations, i.e., transactions that change the state of the blockchain
export const walletClients = chains.map((chain) =>
createWalletClient({
chain,
transport: http(),
})
);
export const getWalletClient = (chainId: number) => {
const client = walletClients.find((client) => client.chain.id === chainId);
if (!client) throw new Error(`Unsupported chain ID: ${chainId}`);
return client;
};
// Create wagmiConfig
export const config = createConfig({
chains: chains,
transports: {
[optimism.id]: http(process.env.ALCHEMY_RPC_OP),
[base.id]: http(process.env.ALCHEMY_RPC_BASE),
[optimismSepolia.id]: http(process.env.ALCHEMY_RPC_OP_SEPOLIA),
},
connectors: [
walletConnect({ projectId, metadata, showQrModal: false }),
injected({ shimDisconnect: true }),
coinbaseWallet({
appName: metadata.name,
appLogoUrl: metadata.icons[0],
preference: "all",
}),
authConnector({
chains,
options: { projectId },
email: false, // default to true
socials: ["farcaster"],
showWallets: true, // default to true
walletFeatures: true, // default to true
}),
],
ssr: true,
});