
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
web3modal-vue3
Advanced tools
A single Web3 / Ethereum provider solution for all Wallets
A single Web3 / Ethereum provider solution for all Wallets
Forked for Vue3 compatibility from the excellent work done by @SmallRuralDog, whose original web3modal-vue package may be found at https://github.com/SmallRuralDog/web3modal-vue.
Web3Modal is an easy-to-use library to help developers add support for multiple providers in their apps with a simple customizable configuration.
By default Web3Modal Library supports injected providers like (Metamask, Dapper, Gnosis Safe, Frame, Web3 Browsers, etc) and WalletConnect, You can also easily configure the library to support Portis, Fortmatic, Squarelink, Torus, Authereum, D'CENT Wallet and Arkane.
npm install --save web3modal-vue3
# OR
yarn add web3modal-vue3
/* See Provider Options Section */
<template>
<div id="app">
<web3-modal-vue
ref="web3modal"
:theme="theme"
:provider-options="providerOptions"
cache-provider
/>
</div>
</template>
<script>
import Web3ModalVue from "web3modal-vue3"
import WalletConnectProvider from "@walletconnect/web3-provider"
import { web3Modal } from "./config/mixins"
import Header from "@/components/Header"
export default {
components: {
Header,
Web3ModalVue
},
mixins: [web3Modal],
data() {
return {
theme: "light",
providerOptions: {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: "-"
}
}
},
number: 0,
balance: 0
}
},
created() {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
this.theme = "dark"
}
},
mounted() {
this.$nextTick(async () => {
const web3modal = this.$refs.web3modal
this.$store.commit("setWeb3Modal", web3modal)
if (web3modal.cachedProvider) {
await this.$store.dispatch("connect")
this.subscribeMewBlockHeaders()
}
})
},
methods: {
connect() {
this.$store.dispatch("connect")
}
}
}
</script>
import { getLibrary } from "@/utils/web3"
import { ethers } from "ethers"
import { parseInt } from "lodash"
const web3ModalStore = {
state: {
web3Modal: null,
library: getLibrary(),
active: false,
account: null,
chainId: 0
},
mutations: {
setWeb3Modal(state, web3Modal) {
state.web3Modal = web3Modal
},
setLibrary(state, library) {
state.library = library
},
setActive(state, active) {
state.active = active
},
setAccount(state, account) {
state.account = account
},
setChainId(state, chainId) {
state.chainId = chainId
}
},
actions: {
async connect({ state, commit, dispatch }) {
const provider = await state.web3Modal.connect()
const library = new ethers.providers.Web3Provider(provider)
library.pollingInterval = 12000
commit("setLibrary", library)
const accounts = await library.listAccounts()
if (accounts.length > 0) {
commit("setAccount", accounts[0])
}
const network = await library.getNetwork()
commit("setChainId", network.chainId)
commit("setActive", true)
provider.on("connect", async (info) => {
const chainId = parseInt(info.chainId)
commit("setChainId", chainId)
console.log("connect", info)
})
provider.on("accountsChanged", async (accounts) => {
if (accounts.length > 0) {
commit("setAccount", accounts[0])
} else {
await dispatch("resetApp")
}
console.log("accountsChanged")
})
provider.on("chainChanged", async (chainId) => {
chainId = parseInt(chainId)
commit("setChainId", chainId)
console.log("chainChanged", chainId)
})
},
async resetApp({ state, commit }) {
try {
await state.web3Modal.clearCachedProvider()
} catch (error) {
console.error(error)
}
commit("setAccount", null)
commit("setActive", false)
commit("setLibrary", getLibrary())
}
}
}
export default web3ModalStore
These are all the providers available with Web3Modal and how to configure theirprovider options:
https://github.com/SmallRuralDog/web3modal-vue/tree/master/example
https://smallruraldog.github.io/web3modal-vue
MIT
FAQs
A single Web3 / Ethereum provider solution for all Wallets
The npm package web3modal-vue3 receives a total of 0 weekly downloads. As such, web3modal-vue3 popularity was classified as not popular.
We found that web3modal-vue3 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.