0.1.6 • Published 2 years ago

solana-wallets-vue-2 v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Solana Wallets Vue 2

Integrates Solana wallets in your Vue 2 applications.

⚡️ View demo

Installation

To get started, you'll need to install the solana-wallets-vue-2 npm package as well as the wallets adapters provided by Solana.

npm

npm install solana-wallets-vue-2 @solana/wallet-adapter-wallets

yarn

yarn add solana-wallets-vue-2 @solana/wallet-adapter-wallets

Setup

Next, you can install Solana Wallets Vue use as local or global component.
You have to set up Solana Wallets Adapters and prop it to the component instance.

To register as global component:

import { WalletMultiButton } from 'solana-wallets-vue-2'
import 'solana-wallets-vue-2/styles.css'
Vue.component('wallet-multi-button', WalletMultiButton)

To use as a local component:

<template>  
     <div>
        <wallet-multi-button :wallets="wallets" auto-connect />
     </div>
 </template>  
  
<script>  
import {
  CoinbaseWalletAdapter,
  GlowWalletAdapter,
  PhantomWalletAdapter,
  SlopeWalletAdapter,
  SolflareWalletAdapter,
  TorusWalletAdapter,
} from '@solana/wallet-adapter-wallets'

import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'  
import { WalletMultiButton } from 'solana-wallets-vue-2'
import 'solana-wallets-vue-2/styles.css'

export default {
  name: "App",
  components: { WalletMultiButton },
  data() {
    return {
      wallets: [
        new CoinbaseWalletAdapter(),
        new PhantomWalletAdapter(),
        new GlowWalletAdapter(),
        new SlopeWalletAdapter(),
        new SolflareWalletAdapter({ network: WalletAdapterNetwork.Devnet }),
        new TorusWalletAdapter(),
      ],
    };
  },
};   
</script>  

If you prefer the dark mode, simply provide the dark boolean props to the component above.

<wallet-multi-button :wallets="wallets" dark></wallet-multi-button>  

Parameters

Props(Parameter)TypeDefaultDescription
walletsArray[]The wallets available the use.
autoConnectbooleanfalseWhether or not we should try to automatically connect the wallet when loading the page.
autoConnectbooleanfalseWhether or not we should try to automatically connect the wallet when loading the page.
onError(error)voiderror => console.error(error)Will be called whenever an error occurs on the wallet selection/connection workflow.
localStorageKeystringwalletNameThe key to use when storing the selected wallet type (e.g. Phantom) in the local storage.
localStorageKeystringwalletNameThe key to use when storing the selected wallet type (e.g. Phantom) in the local storage.

Usage

You can access the wallet store adding ref to the component instance:

<wallet-multi-button ref="walletConnector" :wallets="wallets" dark></wallet-multi-button>  

Next, you can access by call walletStore in ref:

...  
computed: {  
     publicKey () {
         return this.$refs.walletConnector.walletStore?.publicKey 
     },
}  

walletStore references

The table below shows all the properties and methods you can get from useWallet().

Property/MethodTypeDescription
walletsArrayThe wallets available the use.
autoConnectbooleanWhether or not we should try to automatically connect the wallet when loading the page.
walletWallet | nullThe connected wallet. Null if not connected.
publicKeyPublicKey | nullThe public key of the connected wallet. Null if not connected.
readyStatestringThe ready state of the selected wallet.
readybooleanWhether the selected wallet is ready to connect.
connectedbooleanWhether a wallet has been selected and connected.
connectingbooleanWhether we are connecting a wallet.
disconnectingbooleanWhether we are disconnecting a wallet.
select(walletName)voidSelect a given wallet.
connect()voidConnects the selected wallet.
disconnect()voidDisconnect the selected wallet.
sendTransaction(tx, connection, options)PromiseSend a transation whilst adding the connected wallet as a signer.
signTransactionFunction or undefinedSigns the given transaction. Undefined if not supported by the selected wallet.
signAllTransactionsFunction or undefinedSigns all given transactions. Undefined if not supported by the selected wallet.