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

nod-nft-mint-and-check-token

v0.0.8

Published

This is an NPM package that wraps up a number of javascripts functions that are useful helpers to:

Downloads

13

Readme

Overview

This is an NPM package that wraps up a number of javascripts functions that are useful helpers to:

  • Connect to a user's wallet
  • Check that the user is on the correct network
  • Instantiate a contract using the contrat's address and ABI
  • Mint a token
  • Check if a user already has a token

This functionality is used in this simple demo (checkout the github repository to see usage - specifically the file WalletHasTokenFlowAPI contains most of the usage) that allows a user to connect their wallet, checks to see if their wallet already contains an NFT, and, if it does allows the user to access some placeholder gated content. If the user does not already have the NFT then they can mint one.

Primary Functions

instantiateContract

instantiateContract(contractJSON, provider)

instantiateContract takes an object containing the contract json (contract network, contract address, and contract ABI) and a ethers provider which can be obtained using ethers.js or web3modal.

It will then instantiate a contract that can be read from (queried) or written to (which will require paying gas).

mintWithLifecycleHooks

await mintWithLifecycleHooks = ({ contract, provider, metadataUri, mintPriceInWei, onTransaction, onMint, onFailure })

mintWithLifecycleHooks takes a contract, a provider, a uri that points to artwork or the metadata for artwork, and the price in Wei that will be provided to the minting contract. It also takes callbacks that will be triggered during the minting lifecycle.

It encapsulates the full lifecycle of minting. The callbacks onTransaction, onMint, and onFailure are called when the minting is in progress, when it succeeds, or when it fails. onTransaction is called with the in progress transaction.

providerSignerHasToken

await providerSignerHasToken(provider, contract)

providerSignerHasToken takes a provider and a contract and checks the wallet of the user to see if they have the token in their wallet.

walletTokens

await walletTokens(contract, walletAddress)

walletTokens takes a contract and a wallet address and returns an array of tokenIds that are in the wallet.

Secondary Functions

These functions are used by the primary functions and can be used separately if necessary.

humanReadableMetamaskError

humanReadableMetamaskError(code)

Takes a metamask error code and returns a human-readable error message.

initiateMintWithURIAndPrice

await initiateMintWithURIAndPrice(contract, provider, metadataUri, mintPriceInWei)

initiateMintWithURIAndPrice takes a contract, a provider, a uri that points to artwork or the metadata for artwork, and the price in Wei that will be provided to the minting contract.

It will then mint the NFT and pass back the pending transaction.

waitForContractTransactionToComplete

await waitForContractTransactionToComplete()

A very simple helper method that takes a contract transactionn and waits for it to complete.