Integrating WalletConnect with Vue.js Project on Conflux eSpace
This tutorial guides you through the process of integrating WalletConnect with Web3Modal in a Vue.js project, specifically targeting the Conflux eSpace network. For a hands-on example, check out the GitHub repository Web3modal-Conflux-Vue.
前提条件
- Node.js installed on your computer.
- Basic knowledge of Vue.js and JavaScript.
Step 1: Setting Up Your Vue.js Project
First, create a new Vue.js project using Vite, you can skip this step if you have an existing project. Open your terminal and run the following commands:
npm create vite@latest web3modal-conflux-vue -- --template vue
cd web3modal-conflux-vue
npm install
Step 2: Install Web3Modal and WalletConnect
You need to install Web3Modal and the WalletConnect provider. Run:
npm install @web3modal/wagmi @wagmi/core @wagmi/connectors viem
Step 3: Setting Up Web3Modal
Create a new file named Web3ModalSetup.js
in your project's src
directory, and import the necessary modules to set up WalletConnect.
import { createWeb3Modal } from "@web3modal/wagmi/vue";
import { reconnect, http, createConfig } from "@wagmi/core";
import { confluxESpace } from "@wagmi/core/chains";
import { walletConnect, injected } from "@wagmi/connectors";
// 1. Define constants
const projectId = "YOUR_PROJECT_ID";
const metadata = {
name: "Web3Modal",
description: "Web3Modal Example",
url: "https://web3modal.com", // origin must match your domain & subdomain
icons: ["https://avatars.githubusercontent.com/u/37784886"],
};
const config = createConfig({
chains: [confluxESpace],
transports: {
[confluxESpace.id]: http(),
},
connectors: [
walletConnect({ projectId, metadata, showQrModal: false }),
injected({ shimDisconnect: true }),
],
});
reconnect(config);
// 3. Create modal
createWeb3Modal({
wagmiConfig: config,
projectId,
enableAnalytics: true, // Optional - defaults to your Cloud configuration
enableOnramp: true, // Optional - false as default
});