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

@alphpro/web3-vue

v0.0.4

Published

> `@alphpro/web3-vue` is a series of renderless components and hooks to provide easy access to the Alephium blockchain

Downloads

186

Readme

Alephium Web3-Vue by Alph.Pro

@alphpro/web3-vue is a series of renderless components and hooks to provide easy access to the Alephium blockchain

Install

# install library
bun add @alphpro/web3-vue

# install peer dependencies
bun add \
  @alephium/web3 \
  @alephium/walletconnect-provider \
  @alephium/get-extension-wallet \
  @alephium/walletconnect-qrcode-modal

Setup

Simply import components as needed from @alphpro/web3-vue or initialize the plugin to install the components globally

<script setup lang="ts">
  // use locally in your component
  import {
    AlephiumConnectionProvider,
    AlephiumConnect,
    AlephiumExecute,
  } from "@alphpro/web3-vue";
</script>

~ or ~

// main.ts
import AlphProWeb3 from "@alphpro/web3-vue";

createApp(App)
  .use(AlphProWeb3) // install components globally
  .mount("#app");

Components

Alephium Provider

Alephium Provider should be placed on the furthest edge of your app that you will be using any Alephium features. For most dapps this means wrap your entire app with it for simplicity. Its responsible for resuming with auto-connect, and providing all children components with Alephium functionality

<template>
  <AlephiumConnectionProvider :autoConnect="true" :group="0" network="mainnet">
    <!-- Your App -->
  </AlephiumConnectionProvider>
</template>

Alephium Connect

Alephium Connect can be used anywhere, any time (as long as its a child of AlephiumConnectionProvider). Through its slots API it provides connect, disconnect functionality

Now Add a Connect Button

<template>
  <AlephiumConnect
    v-slot="{ isConnected, connectExtension, connectDesktop, disconnect }"
  >
    <template v-if="!isConnected">
      <button @click="connectExtension">Extension</button>
      <button @click="connectDesktop">Desktop</button>
    </template>
    <button v-else @click="disconnect">Disconnect</button>
  </AlephiumConnect>
</template>

It also provides easy access to the currently connected account

<template>
  <AlephiumConnect v-slot="{ account, balances }">
    <div>Hello {{ account.address }}</div>
    <div>Balance: {{ balances.balance }}</div>
  </AlephiumConnect>
</template>

How you want to show your connect options is completely up to you, one common pattern is to have the 'Connect' button to simply open a modal, and this modal is where the actual connection takes place. Several helper functions are available to make it easy to create such a modal.

<template>
  <AlephiumConnect
    v-slot="{ 
        connectExtension, 
        connectMobile, 
        connectDesktop, 
        connectWalletConnect 
    }"
  >
    <ul>
      <li><button @click="connectExtension">Extension Wallet</button></li>
      <li><button @click="connectMobile">Mobile Wallet</button></li>
      <li><button @click="connectDesktop">Desktop Wallet</button></li>
      <li><button @click="connectWalletConnect">Wallet Connect</button></li>
    </ul>
  </AlephiumConnect>
</template>

Alephium Execute

When creating a dApp, execution of a TxScript is probably something you will encounter. Using the AlephiumExecute component you can provide the generated Artifact & Options and will have access to a simple execute function. Managing signer/provider will be handled behind the scenes. a set of events will be emitted so that you can easily track transaction status

<script setup>
  import { Withdraw } from "../artifacts";

  const fields = {
    initialFields: {},
    attoAlphAmount: DUST_AMOUNT,
  };

  function handleNewTransaction(txId: string) {
    //
  }
  function handleConfirmedTransaction(txId: string) {
    //
  }
  function handleFailedTransaction(txId: string) {
    //
  }
</script>

<template>
  <AlephiumExecute
    :txScript="Withdraw"
    :fields="fields"
    v-slot="{ execute }"
    @txInitiated="handleNewTransaction"
    @txConfirmed="handleConfirmedTransaction"
    @txFailed="handleFailedTransaction"
  >
    <button @click="execute">Withdraw</button>
  </AlephiumExecute>
</template>

Hooks

If you require access to the blockchain from within <script /> tags, a set of hooks are also provided for more raw access. These are what power the above components and are capable of managing more advanced use-cases when needed.

import { useConnect, useAccount, useProvider } from "@alphpro/web3-vue";

const { connect, disconnect, autoConnect } = useConnect();
const { account, balances, fetchBalances } = useAccount();
const { getProvider } = useProvider();

Tips & Troubleshooting

Balances

  1. Balances will be fetched automatically on connection, and refreshed after every successful transaction. Generally you shouldn't need to manually fetch balances, however in some scenarios it may be desired and can be done by simply calling fetchBalances from useAccount()

  2. access to the reactive provider is available from useProvider() however due to management of vue internals, in some cases this will cause issues. The solution is to call the getProvider() getter on demand when needed, and this will return the users untouched provider which you can sign transactions manually for example.

Buffer is not defined

Install Buffer

bun add buffer

Add it to your index.html

import { Buffer } from "buffer";
window.Buffer = Buffer;