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

@samatech/vue3-eth

v0.10.1

Published

Vue3 library for building Dapps in an ES module environment

Downloads

41

Readme

Description

This library relies on the Vue3 composition API. Ethereum activity is handled by Ethers.

Currently, only Metamask is supported as a wallet provider, but work is in progress to integrate WalletConnect and others.

Usage

Install

We recommend PNPM for Javascript package management.

pnpm i -D @samatech/vue3-eth

Configuration

The only configuration is ethChainId, which is an optional string indicating the intended network to connect to. It's only used for error checking, which is skipped if left out.

import { useChain } from '@samatech/vue3-eth';

const chain = useChain({ ethChainId: 'ropsten' });

Callbacks

Callbacks are included in the object returned by useChain.

onSetupProvider

const { onSetupProvider } = useChain();

onSetupProvider((signer) => {
  // The eth provider is connected. Store the signer if you need it later
  // Make sure "signer" is NOT reactive, this will break ethers.js
});

onConnect

const { onConnect } = useChain();

onConnect((address) => {
  // ethers.js setup complete, you can now use all library functions
});

onDisconnect

const { onDisconnect } = useChain();

onDisconnect(() => {
  // Disconnected from blockchain
  // "connectWallet" or "reconnectWallet" must be called to use the library again
});

onChainChanged

const { onChainChanged } = useChain();

onChainChanged((chainId) => {
  // The user changed the blockchain/network
});

onAccountsChanged

const { onAccountsChanged } = useChain();

onAccountsChanged((accounts) => {
  // The user switched accounts
});

Reactive variables

loadingAccount - Boolean indicating whether a connection is in progress. (Default false)

connectError - String/key that represents the current error state. (Default null)

Error descriptions:

  • errors.no_metamask - Metamask is not available in the current browser context
  • errors.not_connected - A blockchain access function was called before a provider was connected
  • errors.user_rejected - The user rejected the transaction
  • errors.nonce_high - The Metamask account nonce doesn't match the expected value. This happens when a local testnet is reset after use, the solution is to go to Metamask options -> Advanced -> Reset Account
  • errors.tx_reverted - The transaction failed for some reason
  • errors.unknown - An unknown error occurred

wrongNetwork - Boolean, true if connected to a network not specified by ethChainId config

walletConnected - Boolean, true if currently connected (after onConnect, before onDisconnect)

Methods

connectWallet(walletName: string)

  • Connect to the blockchain. walletName is the type of wallet, which can be 'metamask' or 'walletconnect'

reconnectWallet(walletName: string)

  • Attempts to automatically reconnect to walletName

disconnectWallet

  • Disconnect the current wallet

getTx(hash: string)

  • Gets a transaction object from a transaction hash

getTxReceipt(hash: string)

  • Gets a transaction receipt object from a transaction hash

getSigner

  • Gets the current signer

getError(e: Exception)

  • Converts an exception to an error key

toEth(value: any)

  • Utility function for converting a value from Wei to Eth. Arg must be a string or implement toString

toEthDisplay(value: any)

  • Utility function that converts a value from Wei to Eth, and returns a human readable number

toWei(value: any)

  • Utility function for converting a value from Eth to Wei (1 / 1e18). Arg must be a string or implement toString

Example

See the example directory (TBD).

License

MIT License © 2021 SamaTech Taiwan