vue-connect-wallet
Bootstrap your decentralized applications by delegating the tedious and repetitive task of wallet connection and button design to this plugin.
Provides a ready-made and fully-customizable UI button and utility functions for connecting to a web3 wallet (MetaMask). It has built-in Typescript support and supports Dark mode.
The button takes care of displaying the user's wallet address, their identicon / avatar and pending transactions.
Utility functions for connecting to a MetaMask wallet are provided. More wallets can be added in the future as per public request. Feel free to contribute yourself!
Getting started
This plugin uses vue-demi
to support both Vue 2 and Vue 3, but usage in Vue 2 is prone to issues, so Vue 3 is the recommended version of vue for this plugin.
Installation
Use Yarn or npm to install the library vue-connect-wallet.
Registering the component
In the main.js
file, import the styles.
Then, you can either register ConnectWalletButton as a global component or specifically import it in the components you need (recommended).
To register as global component, in your main.js
:
To import individually (recommended):
Note: If using <script setup>, you only need to import the component without registering it.
Usage
Button component
If the address
is empty or doesn't start with 0x, the "Connect Wallet" button will be shown. If an address is provided, it will instead display the identicon and the sliced address.
Simple usage
Advanced Usage
MetaMask Utils
Provides functions to easily connect to a MetaMask wallet, get accounts and listen to changes when an account is changed and when a chain/network is changed.
Utilities provided in useMetaMaskWallet
:
Example
Example usage in Vue 3 with Typescript, using <script setup lang="ts">:
Contributing
Conribution in any area is welcome. Adding support for new wallets would be very much appreciated.
To develop in this repo, just clone it and run yarn
to install all the dependencies. Look at the package.json
to understand the scripts.
Miscellaneous
Note on Identicons (Jazzicon)
This package comes with the Jazzicon from the library vue3-jazzicon. Installing it as a dependency in the plugin raised import errors due to which I bundled the component in this plugin itself.
Author
Hi! I am Neelansh Mathur. I am a freelancer specializing in Frontend development for Blockchain applications, and currently studying Computer Engineering. You can find out more about me at my social links.
I made this plugin because I was having to repeatedly use the same code and redesign buttons for every dApp I develop for. This has made my life easier and I hope it does the same for you ?.
Twitter: https://twitter.com/mneelansh15
LinkedIn: https://www.linkedin.com/in/neelansh-mathur/
Dev.to: https://dev.to/neelansh15
Github: https://github.com/neelansh15