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

@usekeyp/js-sdk

v0.1.8-staging.1

Published

Tools for building apps using Keyp

Downloads

5

Readme

Easily manage wallets, enable SSOs, interact with smart contracts and more with just a few lines of code

Currently, the SDK supports the following:

  • Use the Keyp SDK and ui-kit to quickly set up authentication
  • ERC20 and ERC721 token transfers
  • Read and write smart contracts

Install 📦

yarn add @usekeyp/js-sdk

Usage 📖

Authentication

Configure using the Keyp NextAuth provider

// pages/api/auth/[...nextauth].ts
import { Keyp } from "@usekeyp/js-sdk";
import NextAuth, {Account, CallbacksOptions, NextAuthOptions, Profile} from "next-auth";

// Define the callbacks needed to expose the Keyp user data to the client
const callbacks : Partial<CallbacksOptions<Profile, Account>> | undefined = {
    async jwt({token, account, profile}) {
        if (account) {
            // Comes from the returned JWT from Keyp
            token.accessToken = account.access_token;
        }
        if (profile) {
            // Comes from the /userinfo endpoint
            token.username = profile.username;
            token.address = profile.address;
            if (profile.sub != null) {
                token.sub = profile.sub;
            }
        }
        return token;
    },
    async session({ session, token }) {
        // Send properties to the client, like an access_token from a provider.
        if (token) {
            session.user.accessToken = token.accessToken;
            session.user.username = token.username;
            session.user.address = token.address;
            session.user.id = token.sub;
        }
        return session;
    },
}

const keypAuthOptions: NextAuthOptions = {
    providers: [
        //@ts-expect-error issue https://github.com/nextauthjs/next-auth/issues/6174
        Keyp({
            clientId: process.env.KEYP_CLIENT_ID || '', // From dev portal
            clientSecret: process.env.KEYP_COOKIE_SECRET || '', // Random string
        }),
    ],
    callbacks: callbacks,
}

export default NextAuth(keypAuthOptions);

Trigger a login for a specific social provider using signInKeyp()

import { signInKeyp } from "@usekeyp/js-sdk"

export default function SignInPage() {
    return (
        <div>
        <button onClick={() => signInKeyp("GOOGLE")}>Sign in with Google</button>
        <button onClick={() => signInKeyp("DISCORD")}>Sign in with Discord</button>
        </div>
    )
}

Currently, the SDK supports the following:

  • A Keyp plugin for integration between Keyp and NextAuth.js (keyp-auth.ts)
  • Helper method for signing in using Keyp and NextAuth.js (keyp-helpers.ts)
  • Helper tokenTransfer method for token transfers (token-helpers.ts)
  • Helper readContract and writeContract methods for interacting with smart contracts (contract-helpers.ts)
  • Helper retrieveListings method for retrieving OpenSea listings (opensea-helpers.ts)
  • Axios client for easily making requests to Keyp's API (keypClient.ts)

ERC20 and ERC721 token transfers

import { tokenTransfer } from "@usekeyp/js-sdk";
import { useSession } from "next-auth/react";

const { data: session } = useSession();
const ACCESS_TOKEN = session.user.accessToken

const data = {
    accessToken: ACCESS_TOKEN,
    toUserUsername: "pi0neerpat#1337",
    toUserProviderType: "DISCORD",
    tokenAddress: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063',
    tokenType: 'ERC20',
    amount: '.01',
}

const result = await tokenTransfer(data)

Read and write smart contracts

import { readContract, writeContract } from "@usekeyp/js-sdk";
import { useSession } from "next-auth/react";

const { data: session } = useSession();
const ACCESS_TOKEN = session.user.accessToken

// Read from a smart contract
const resultWrite = await readContract(
    {
        accessToken: ACCESS_TOKEN,
        address: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
        abi: "balanceOf(address) public view returns (uint256)",
        args: ['0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'],
    });

// Write to a smart contract
const resultRead = await writeContract(
    {
        accessToken: ACCESS_TOKEN,
        address: "0x55d4dfb578daa4d60380995fff7a706471d7c719",
        abi: "pay(uint256,uint256,address) public returns (bool success)",
        args: ['1', '10000000', '0x9ca6a77c8b38159fd2da9bd25bc3e259c33f5e39'],
    });

Resources 🧑‍💻

For more instructions, see the Docs.

License 📝

Copyright © 2023 Nifty Chess, Inc. This project is MIT licensed.