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

use-cmv3

v1.0.6

Published

React library for interacting with metaplex candy machine v3

Downloads

229

Readme

use-cmv3

MIT License

React library enabling you to interact with the Metaplex candy machine

(This library currently only supports the following guards solPayment allowList mintLimit startDate endDate)

Demo: Cmv3 Frontend

Todo:

  • [ ] Support all guards

  • [ ] Phase Metadata

  • [ ] Multi-Mint

Installation

npm install \
  "use-cmv3" \
  "@metaplex-foundation/mpl-candy-machine" \
  "@metaplex-foundation/mpl-token-metadata" \
  "@metaplex-foundation/mpl-toolbox" \
  "@metaplex-foundation/umi" \
  "@metaplex-foundation/umi-bundle-defaults" \
  "@metaplex-foundation/umi-rpc-web3js" \
  "@metaplex-foundation/umi-signer-wallet-adapters" \
  "@metaplex-foundation/umi-uploader-nft-storage" \
  "@solana/wallet-adapter-base" \
  "@solana/wallet-adapter-react" \
  "@solana/wallet-adapter-react-ui" \
  "@solana/wallet-adapter-wallets" \
  "@solana/web3.js"

Using inside your project

Add the following to your .env file

NEXT_PUBLIC_CANDY_MACHINE_ID={your_cm_id}
NEXT_PUBLIC_CANDY_MACHINE_LUT={your_cm_lut}
NEXT_PUBLIC_ENDPOINT={your_endpoint}

Wrap necessary components within Cmv3Provider, ensuring that WalletAdapter is an ancestor.

import { WalletProvider } from  '@solana/wallet-adapter-react'
import { Cmv3Provider } from 'use-cmv3'

export default function App({children}) {
    
    /* wallet adapter stuff */
    
    const  allowLists  =  new  Map<string, Array<string>>([['OGs', ['61DZsc2GKvgygUMgmNcYmT2jVjdJmxWEiPyn3nfJW3Td']]])
    
    return (
        <WalletProvider>
            <Cmv3Provider
                config={{
                    candyMachineId: process.env.NEXT_PUBLIC_CANDY_MACHINE_ID,
                    candyMachineLut: process.env.NEXT_PUBLIC_CANDY_MACHINE_ID
                }}
                metadata={{
                    allowLists: allowLists
                }}
            >
                {children}
            </Cmv3Provider>
         </WalletProvider>
    )
}

You can now call useCmv3() inside wrapped components.

import { useCmv3 } from 'use-cmv3'

export  default  function  Mint() {

    const cmv3 = useCmv3()
    
    return (
        <main>
        
            <h1>Mint Page!</h1>
        
            <Counter
                value={mintCounter.sold} 
                maxValue={mintCounter.supply}
            />
            
            <Phases>
                {cmv3.phases.map(phase => (
                    <Phases.Phase phase={phase}/>
                ))}
            </Phases
        </main>
    
    )
}

Context Values

Values returned by useCmv3()

|Name | Type | Description | Default | |--|--|--|--| | loading | { candyMachine: boolean, phases: boolean} | Loading values for the whole candyMachine or just phases | { candyMachine: true, phases: true } | | candyMachine? | CandyMachine | Returns the initialised candy machine if applicable | undefined | | candyGuard? | CandyGuard | Returns the initialised candy machines guard if applicable | undefined | | phases | Phase[]| Array of phases relative to the connected wallet | [] | | mintCounter | { supply: number; sold: number; } | Exposes sold/supply statistics of candy machine | { supply: 0; sold: 0 } | | minting | string / false | Label of the phase user is currently minting | false | | mint | (label: string) => Promise<void> | Function to mint a phase with label | | | mints | { mints: string; metadata: JsonMetadata }[] | Array of NFTs minted by user | [] |

Phases:

Phases are an interpolation of candy guard groups.

| Name | Type | Description | |--|--|--| | label | string | Label of the guard candy guard group | | errors | string[] | Guards stopping the user from minting | | payments | { basisPoints: number; decimals: number; identifier: string; } | Payment guards formatted into Payment | | startsAt? | number | UNIX timestamp of the phases start date | | endsAt? | number | UNIX timestamp of the phases end date

Notes

This library is un-audited and not affiliated with Solana or Metaplex.

Big thanks to MarkSackerberg who's work I often referenced while creating this library.