npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web3modal-vue3

v1.3.4

Published

A single Web3 / Ethereum provider solution for all Wallets

Downloads

69

Readme

Web3ModalVue bump

A single Web3 / Ethereum provider solution for all Wallets

Origins

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.

Introduction

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.

React

web3modal

Usage

  1. Install Web3Modal NPM package
npm install --save web3modal-vue3

# OR

yarn add web3modal-vue3
  1. Install Provider packages
/* See Provider Options Section */
  1. Then you can add Web3Modal to your Dapp as follows
<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

Provider Options

These are all the providers available with Web3Modal and how to configure theirprovider options:

Who using it

Submit my Dapp

Example

https://github.com/SmallRuralDog/web3modal-vue/tree/master/example

Demo

https://smallruraldog.github.io/web3modal-vue

License

MIT