百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

solana-wallets-vue

> 前端框架
开源

Solana 钱包集成到 Vue 3 中

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Solana 钱包集成到 Vue 3 中

Solana Wallets Vue

Integrates Solana wallets in your Vue 3 applications.

⚡️ View demo / Browse demo code

Installation

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

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

Setup

Next, you can install Solana Wallets Vue as a plugin like so.

…

This will initialise the wallet store and create a new $wallet global property that you can access inside any component.

Note that you can also initialise the wallet store manually using the initWallet method like so.

javascript
import { initWallet } from "solana-wallets-vue";
initWallet(walletOptions);

Finally, import and render the WalletMultiButton component to allow users to select a wallet et connect to it.

xml

  

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

xml

Usage

You can then call useWallet() at any time to access the wallet store — or access the $wallet global propery instead.

Here's an example of a function that sends one lamport to a random address.

…

Anchor usage

If you're using Anchor, then you might want to define your own store that encapsulates useWallet into something that will also provide information on the current connection, provider and program.

…

This allows you to access the Anchor program anywhere within your application in just a few lines of code.

javascript
import { useWorkspace } from "./useWorkspace";

const { program } = useWorkspace();
await program.value.rpc.myInstruction(/* ... */);

Configurations

The table below shows all options you can provide when initialising the wallet store. Note that some options accepts Ref types so you can update them at runtime and keep their reactivity.

Option Type Description
wallets Adapter[] | Ref The wallet adapters available the use. Defaults to [].
autoConnect boolean | Ref Whether or not we should try to automatically connect the wallet when loading the page. Defaults to false.
cluster Cluster | Ref The Solana cluster used by the wallets. Defaults to mainnet-beta.
onError(error: WalletError) void Will be called whenever an error occurs on the wallet selection/connection workflow. Defaults to error => console.error(error).
localStorageKey string The key to use when storing the selected wallet type (e.g. Phantom) in the local storage. Defaults to walletName.

useWallet() references

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

Property/Method Type Description
wallets Ref The wallets available the use.
autoConnect Ref Whether or not we should try to automatically connect the wallet when loading the page.
cluster Ref The Solana cluster used by the wallets — e.g. mainnet-beta.
wallet Ref The connected wallet. Null if not connected.
publicKey Ref The public key of the connected wallet. Null if not connected.
readyState Ref The ready state of the selected wallet.
ready Ref Whether the selected wallet is ready to connect.
connected Ref Whether a wallet has been selected and connected.
connecting Ref Whether we are connecting a wallet.
disconnecting Ref Whether we are disconnecting a wallet.
select(walletName) void Select a given wallet.
connect() Promise Connects the selected wallet.
disconnect() Promise Disconnect the selected wallet.
sendTransaction Function Send a transation whilst adding the connected wallet as a signer.
signTransaction Function or undefined Signs the given transaction. Undefined if not supported by the selected wallet.
signAllTransactions Function or undefined Signs all given transactions. Undefined if not supported by the selected wallet.
signMessage Function or undefined Signs the given message. Undefined if not supported by the selected wallet.

Nuxt 3 Setup

  1. Create a new plugin, ex. plugins/solana.ts
typescript
import "solana-wallets-vue/styles.css";
import SolanaWallets from "solana-wallets-vue";
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
import {
  PhantomWalletAdapter,
  SlopeWalletAdapter,
  SolflareWalletAdapter,
} from "@solana/wallet-adapter-wallets";

const walletOptions = {
  wallets: [
    new PhantomWalletAdapter(),
    new SlopeWalletAdapter(),
    new SolflareWalletAdapter({ network: WalletAdapterNetwork.Devnet }),
  ],
  autoConnect: true,
};

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(SolanaWallets, walletOptions);
});
  1. Update the nuxt.config.ts
typescript
export default defineNuxtConfig({
  modules: ["@nuxtjs/tailwindcss"],
  vite: {
    esbuild: {
      target: "esnext",
    },
    build: {
      target: "esnext",
    },
    optimizeDeps: {
      include: ["@coral-xyz/anchor", "@solana/web3.js", "buffer"],
      esbuildOptions: {
        target: "esnext",
      },
    },
    define: {
      "process.env.BROWSER": true,
    },
  },
});
  1. On your app.vue
xml

  
    
  

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptsolanavuewallet

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架