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

wen-connect

v1.2.1

Published

[![Version](https://img.shields.io/npm/v/wen-connect?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/wen-connect) [![Build Size](https://img.shields.io/bundlephobia/minzip/wen-connect?label=bundle%20size&style=flat&colorA=000000&col

Downloads

10

Readme

Wen Connect? Now!

Version Build Size Downloads

Minimalistic library for Web3 user interfaces.

  • Seamless connection flows to Metamask.
  • Stateless sessions that work anywhere (client, serverless, Edge Functions).
  • Respectful of user privacy. Take only the needed information, nothing more. Never saved to a DB.

Wen is about getting you to build Web3 instead of figuring out the patch work of software needed.

Usage

yarn add wen-connect
# or
npm install wen-connect --save

Wen works in all JavaScript applications, but offers different bindings for different frameworks.

React


One single context: WenProvider, and one hook: useWen for everything.

Add WenProvider to your root component:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { WenProvider } from "wen-connect";

ReactDOM.render(
  <React.StrictMode>
    <WenProvider>
      <App />
    </WenProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Use the hook to engage with your user:

import { useWen } from "wen-connect";

const MyComponent = () => {
  const { connect, disconnect, wallet } = useWen();

  const handleConnect = () => {
    // Optional argument to specify which chain to get the user connected on.
    connect({ chainId: "0xa86a" });
  };

  const handleDisconnect = () => {
    disconnect();
  };

  return <span>{wallet.address}</span>;
};

wallet contains the following info:

address: string
balance: Hex string
chainId: Hex string
connected: boolean
connector: "injected"

Next.js


Wen also works server-side with Next.js to let you connect. Activate the ssr prop in the provider and add your provider to _app.tsx:

import { WenProvider } from "wen-connect";

function MyApp({ Component, pageProps }) {
  const config = { ssr: true };
  return (
    <WenProvider config={config}>
      <Component {...pageProps} />
    </WenProvider>
  );
}

Create a pages/api/wen.tsx for Wen to use JWT sessions:

export { WenConnect as default } from "wen-connect";

Add a WEN_SECRET environment variable in your .env file. It will be used to encrypt the JWT token.

Now, you can get the session in getServerSideprops and use it to hydrate Wen on the client-side first render.

import { getSession, useWen } from "wen-connect";

function Index(props) {
  // Passing the session will avoid empty initial renders, saving your users loading time.
  const { wallet } = useWen(props.session);

  return <div>{wallet.address}</div>;
}

export default Index;

export const getServerSideProps = async (context) => {
  return {
    props: {
      // session.wallet is the same info as const { wallet } = useWen(props session);
      session: getSession(context),
    },
  };
};

Roadmap:

  • Signing in desired user state.
  • Svelte and SvelteKit bindings.
  • Wallet connect.
  • Coinbase wallet.
  • The graph integrations.
  • More examples.