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

@thesellouts/sellout-hooks

v0.1.30

Published

react hooks for interacting with sellout protocol

Downloads

14

Readme

@thesellouts/sellout-hooks

This package provides a set of hooks and SDK functions for interacting with the Sellout protocol, designed to facilitate managing shows, artists, organizers, venues, and referrals on the blockchain. The hooks utilize TanStack React Query under the hood for data fetching and caching.

Installation

You can install the package using npm or yarn:

pnpm install @thesellouts/sellout-hooks

or

yarn add @thesellouts/sellout-hooks

or

npm add @thesellouts/sellout-hooks

Smart Account Support

This package supports both EOA (Externally Owned Accounts) and smart accounts using the permissionless library. Here's how it works:

  • With Provider: If you pass smartAccountClient to the SelloutProvider, by default it will always use the smart account to execute functions. You can override this by passing { smart: false } in the options argument of an SDK function call.

  • With Hooks: By default, hooks use an EOA. To use a smart account, pass smartAccountClient in the options object when calling a hook.

Usage

Client-Side Usage (Hooks)

You can use the provided hooks directly without needing to wrap your application in a provider. However, you must provide the chainId when using the hooks. The hooks allow you to access the Sellout protocol's functionalities easily and use TanStack React Query for efficient data fetching and caching.

Here's an example of using a hook:

import React from 'react';
import { useVote } from '@thesellouts/sellout-hooks';
import { base } from 'viem/chains';
import { SmartAccountClient } from 'permissionless';

const VoteComponent = ({ showId, proposalIndex }) => {
  const chainId = base.id;
  const smartAccountClient = /* your SmartAccountClient initialization */;

  const { mutate, isLoading, error } = useVote(
    { showId, proposalIndex, chainId },
    { smartAccountClient } // Optional: Use smart account
  );

  const handleVote = () => {
    mutate();
  };

  if (isLoading) return <div>Voting...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return <button onClick={handleVote}>Vote</button>;
};

export default VoteComponent;

Server-Side Usage (SDK Functions)

To use SDK functions on the server-side, you need to initialize the SDK instance. Here's an example of using an SDK function:

import { SelloutSDK } from '@thesellouts/sellout-hooks'
import { base } from 'viem/chains'

const handleVote = async () => {
  const chainId = base.id
  const sdk = new SelloutSDK(chainId)

  try {
    const result = await sdk.vote(
      { showId: '123', proposalIndex: 0 },
      { smart: false } // Optional: Force EOA usage even if smartAccountClient is provided
    )
    console.log('Vote cast:', result)
  } catch (error) {
    console.error('Error casting vote:', error)
  }
}

Provider (Optional for Client-Side SDK Usage)

If you need to use SDK functions on the client-side, you can wrap your application in the SelloutProvider. This provider initializes the SDK instance and makes it available throughout your application.

Here's how to create and use the provider:

import React from 'react';
import { SelloutProvider } from '@thesellouts/sellout-hooks';
import { SmartAccountClient } from 'permissionless';
import YourComponent from './YourComponent';

const App = () => {
  const chainId = base.id;
  const smartAccountClient = /* your SmartAccountClient initialization */;

  return (
    <SelloutProvider chainId={chainId} smartAccountClient={smartAccountClient}>
      <YourComponent />
    </SelloutProvider>
  );
};

export default App;

Then, in your components, you can use the useSellout hook to access the SDK instance:

import React from 'react'
import { useSellout } from '@thesellouts/sellout-hooks'

const SomeComponent = () => {
  const { sdk } = useSellout()

  const handleVote = async () => {
    try {
      const result = await sdk.vote(
        { showId: '123', proposalIndex: 0 },
        { smart: false } // Optional: Explicitly don't use smart account (default if smartAccountClient is provided)
      )
      console.log('Vote cast:', result)
    } catch (error) {
      console.error('Error casting vote:', error)
    }
  }

  return <button onClick={handleVote}>Vote</button>
}

export default SomeComponent

Summary

  • Use hooks without a provider for easy access to Sellout functionalities on the client-side, providing chainId with each hook call.
  • Use SDK functions directly for server-side operations.
  • Optionally wrap your application in SelloutProvider for client-side SDK usage.
  • Hooks utilize TanStack React Query for efficient data handling.
  • Smart account support is available using the permissionless library:
    • With provider: Smart account used by default, override with { smart: false }.
    • With hooks: EOA used by default, use smart account by passing smartAccountClient in options.

For more details, refer to the individual function and hook documentation in their respective files.