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

@3swallet.js/web3-onboard-connector

v1.0.3

Published

Web3-onboard connectors for 3S Wallet supported third-party: - [web3-onboard](https://github.com/blocknative/web3-onboard)

Downloads

8

Readme

@3swallet.js/web3-onboard-connector

Web3-onboard connectors for 3S Wallet supported third-party:

For more details, read the documentation

Installation

  • yarn:
yarn add @3swallet.js/-connector
  • npm:
npm install @3swallet.js/web3-onboard-connector

Quick start

import Web3OnBoardConnector from '@3swallet.js/web3-onboard-connector';
import { useState } from 'react';
import walletConnectModule from '@web3-onboard/walletconnect';
import injectedModule from '@web3-onboard/injected-wallets';
import Onboard from '@web3-onboard/core';

const toHex = (num: number): string => {
  const val = Number(num);
  return '0x' + val.toString(16);
};

const ETH_RPC_URL = `https://mainnet.infura.io/v3/${process.env.INFURA_KEY}`;
const BNB_RPC_URL = `https://bscrpc.com`;

const wallet3S = Web3OnBoardConnector({
  rpc: {
    1: `https://mainnet.infura.io/v3/${process.env.infuraKey}`,
    56: 'https://bscrpc.com',
  },
});
const walletConnect = walletConnectModule();
const injected = injectedModule();
const onboard = Onboard({
  wallets: [wallet3S, walletConnect, injected],
  chains: [
    {
      id: toHex(1), // chain ID must be in hexadecimel
      token: 'ETH',
      namespace: 'evm',
      label: 'Ethereum Mainnet',
      rpcUrl: ETH_RPC_URL,
    },
    {
      id: toHex(56),
      token: 'BNB',
      namespace: 'evm',
      label: 'BNB Chain',
      rpcUrl: BNB_RPC_URL,
    },
  ],
  appMetadata: {
    name: 'My App',
    icon: 'https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svg',
    logo: 'https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svg',
    description: 'My app using Onboard',
    recommendedInjectedWallets: [
      { name: 'MetaMask', url: 'https://metamask.io' },
    ],
  },
});

export function Index() {
  const [_, setProvider] = useState<any>(null);
  const [account, setAccount] = useState<string>('');
  const [chainId, setChainId] = useState<number | string>(0);
  const [isLoading, setIsLoading] = useState(false);

  const connectWallet = async () => {
    try {
      const wallets = await onboard.connectWallet();
      setIsLoading(true);
      const { accounts, chains, provider } = wallets[0];
      setAccount(accounts[0].address);
      setChainId(chains[0].id);
      setProvider(provider);
      setIsLoading(false);
    } catch (error) {
      console.error(error);
    }
  };

  const disconnect = async () => {
    const [primaryWallet] = await onboard.state.get().wallets;
    if (!primaryWallet) return;
    await onboard.disconnectWallet({ label: primaryWallet.label });
    setAccount('');
    setChainId(0);
    setProvider(null);
  };

  return (
    <div className="wrapper">
      <div className="container">
        <div id="welcome">
          <h1>{`Let's connect with 3S Wallet`}</h1>
        </div>
        <div id="content">
          <div className="connection">
            {!account ? (
              <button onClick={connectWallet}>Connect</button>
            ) : (
              <button className="disconnect" onClick={disconnect}>
                Disconnect
              </button>
            )}
          </div>
          {isLoading && <div>Loading...</div>}
          <div className="status">
            Connection Status:
            {!account ? (
              <strong>Disconnected</strong>
            ) : (
              <strong>Connected</strong>
            )}
          </div>
          <div className="status">
            Account: <strong>{account}</strong>
          </div>
          <div className="status">
            Chain ID: <strong>{chainId}</strong>
          </div>
        </div>
      </div>
    </div>
  );
}

export default Index;