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

toshi-gating

v1.0.0

Published

If you're developing utilities around toshi, feel free to use it

Downloads

41

Readme

Toshi Gating

Toshi Gating is a package designed to provide gating functionality for projects utilizing Toshi.

Table of Contents

Installation

You can install Toshi Gating via npm:

npm install toshi-gating

Environment Setup

To run this project, create a .env file at the root with the following variables:

  • QUICKNODE_HTTPS_URL: HTTPS URL for QuickNode endpoint.
  • NEYNAR_API_KEY: API key for Neynar service.

Example .env

QUICKNODE_HTTPS_URL=https://your-node.quicknode.com
NEYNAR_API_KEY=your-neynar-api-key

Important: Do not commit the .env file to your repository. Ensure it's in your .gitignore.

Usage

To use Toshi Gating in your project, import it and utilize its functions as needed:

For now, it only support 2 service provider.

Farcaster Frame

This example demonstrates how to use the toshi-gating package to check if a user holds a token, given their Farcaster ID (FID) and minimal amount toshi required. Ensure you have a .env file set up with the required environment variables before running the example.


import Toshi from "toshi-gating";

const toshi = new Toshi();
const isHolder = await toshi.isHolder(FID, 1000);

ES6

QuickNode SDK

Here is QuickNode

import Toshi, {QuickNodeServiceProvider} from "toshi-gating";

const toshi = new Toshi(new QuickNodeServiceProvider(QUICKNODE_HTTPS_URL));
const isHolder = await toshi.isHolder(USER_WALLET_ADDRESS);//minimum 1 Toshi

Viem SDK

it use mainnet basescan API

import Toshi, {ViemServiceProvider} from "toshi-gating";

const toshi = new Toshi(new ViemServiceProvider());
const isHolder = await toshi.isHolder(USER_WALLET_ADDRESS,10);//minimum 10 toshi

Custom Service Provider SDK

You can implement your custom service provider and provide additional functionality. Below is an example of how you can create a custom service provider using the IEthServiceProvider interface provided by toshi Gating:

import Toshi, { IEthServiceProvider, EthAddress } from "toshi-gating";

export default class CustomServiceProvider implements IEthServiceProvider {
    async balanceOf(userWalletAddress: EthAddress, amount: Number = 1): Promise<number> {
        // Your implementation here
    }
}

and then you can use it:

import Toshi from "toshi-gating";

const toshi = new Toshi(new CustomServiceProvider());
const isHolder = await toshi.isHolder(USER_WALLET_ADDRESS,1000);//minimum holding 1000 toshi

cjs

async function loadModule() {
    return await import('toshi-gating');
}

(async()=>{
    const Toshi = await loadModule();

    const a = new Toshi.default(new Toshi.QuickNodeServiceProvider(QUICKNODE_HTTPS_URL));

    console.log("a",await a.isHolder(USER_WALLET_ADDRESS));

    const b = new Toshi.default(new Toshi.ViemServiceProvider());

    console.log("b",await b.isHolder(USER_WALLET_ADDRESS));
})();

Contributing

Contributions to Toshi Gating are welcome! If you find any issues or have suggestions for improvements, please open an issue or create a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

Feel free to include this Markdown content in your documentation. Let me know if you need further assistance!