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

@nameless-nft/react

v1.0.0

Published

A collection of hooks to help you interface with your nameless environments.

Downloads

3

Readme

@nameless-nft/react

A collection of hooks to help you interface with your nameless environments.

Setup

Install NamelessProvider

You need this at the root level of your application.

const config = require('./nameless.json');

const NamelessApp = () => (
  <NamelessProvider config={config}>
    <App />
  </NamelessProvider>
);

Web3 Client

chainId, provider and account are required properties, you can get them from a web3 client like @web3-react.

const config = require('./nameless.json');

const NamelessApp = () => {
  const { chainId, provider, account } = useWeb3React();
  return (
    <NamelessProvider
      config={config}
      chainId={chainId}
      provider={provider}
      account={account}
    >
      <App />
    </NamelessProvider>
  );
};

Hooks

useActivateListing

If you're using the dutch_auction contract, you need to activate an auction listing before parties can bid.

const listingId = 1;
const [activateListing, { loading }] = useActivateListing();

return (
  <button
    onClick={async () => {
      const tx = await activateListing(listingId);
      const receipt = await tx.wait();
    }}
  >
    {loading
      ? 'Please approve tx in your wallet'
      : `Activate Auction Listing #${listingId}`}
  </button>
);

useActivateSalesContract

If you're using the nameless_sales contract, you'll need to activate before it's ready to accept purchases. You can use this function to help you do that.

It's also possible to de-activate the sales contract, just pass it false.

const [activateSalesContract] = useActivateSalesContract();

const onClick = async () => {
  await activateSalesContract(true);
};

useDutchAuctionListings

If you're using dutch auctions, this is how you access the active listings.

const [bid] = useBid();
const [listings] = useDutchAuctionListings();

return (
  <div>
    {listings.map((listing, index) => (
      <div>
        Auction #{index}
        Ends: {listing.endTime}
        Final price: {listing.finalPrice}
        {listing.calculatedPrice.toString()} ETH
        <button
          onClick={() => {
            bid(index);
          }}
        >
          Bid
        </button>
      </div>
    ))}
  </div>
);

useGrantRole

gives the owner account the ability to grant an account a role on the token contract. There are two roles on the token contract: minter and redeemer.

const [grantRole] = useGrantRole();

return (
  <button
    onClick={async () => {
      const tx = await grantRole('minter', '0x...');
      await tx.wait();
    }}
  >
    Grant Minter Role
  </button>
);

useHasRole

Query the token contract and determine if an address has a specific role.

const { data: canMint, loading } = useHasRole('minter');

return canMint && <button>Mint</button>;

useIsSalesActive

Returns a boolean indicating whether or not sales contract is active.

const { data: isSalesActive } = useIsSalesActive();

return isSalesActive && <button>Purchase</button>;

useIsTokenContractOwner

Returns a boolean indicating whether or not the active account (or provided address) is the owner of the token contract.

const isOwner = useIsTokenContractOwner();

return isOwner && <button>For admins only!</button>;

useMint

const [mint] = useMint();

return (
  <button
    onClick={async () => {
      const tokenId = 100;
      const tx = await mint(tokenId);
      const receipt = await tx.wait();
    }}
  >
    Mint
  </button>
);

useMintedNFTs

Easily list your collection's minted tokens and available attributes with this hook. It returns a list of tokens and an attribute in the form of a Map. Here's an example of how you might use it.

const { data } = useMintedNFTs();
const { tokens = [], attributes = new Map() } = { ...data };

// attributes:
// "Size" => ["Smol", "Smedium", "Bigly"]
// "Color" => ["Blue", "Red", "Yellow"]

return (
  <>
    <div>
      <h2>Attributes</h2>
      <ul>
        {Array.from(attributes.keys).map((traitType) => (
          <li>
            {traitType}
            <ul>
              {attributes.get(traitType)?.map((value) => (
                <li>{value}</li>
              ))}
            </ul>
          </li>
        ))}
      </ul>
    </div>

    <div>
      {tokens.map(({ name, description, image, attributes }) => (
        <img src={image} />
        <h3>{name}</h3>
        <p>{description}</p>
        {attributes.map(({ trait_type, value }) => (
          <div>
            <h4>{trait_type}</h4>
            <div>{value}</div>
          </div>
        ))}
      ))}
    </div>
  </>
);

useNameless

This is a general hook for accessing nameless configuration, deployment data, contracts, wallet configuration information and more.

const {
  config,
  deployment,
  isConnected,
  providerUrl,
  chainId,
  selectedChainId,
  ...andMore
} = useNameless();

useNamelessState

This is generally an internal method, but you can use it to query and mutate the nameless state. This is not recommended for basic usage.

const [state, setState] = useNamelessState();

usePurchase

Use this to execute a purchase transaction against a nameless_sales contract.

const [purchase] = usePurchase();

return (
  <button
    onClick={() => {
      const quanity = 1;
      const tx = await purchase(quantity);
      const receipt = await tx.wait();
    }}
  >
    Purchase
  </button>
);

useSalesContract

Interact with the sales contract abi

const auctionListingId = 1;
const salesContract = useSalesContract();
const price = await salesContract?.calculateCurrentPrice(auctionListingId);

useTokenContract

Interact with the token contract abi

const tokenId = 1;
const address = '0x...';
const tokenContract = useTokenContract();
const tx = await tokenContract.mint(tokenId, address);
const receipt = await tx.wait();

useTokenData

Query token data

const tokenIds = [1, 2, 3, 4, 5];
const { data: tokenData } = useTokenData(tokenIds);

return (
  <div>
    {tokenData.map(token => (
      <div>
        <img src={token.image} width={100} />
        <h3>{token.name}</h3>
        <p>{token.description}</p>
        <ul>
          {token.attributes.map(attr => (
            <li>
              {attr.trait_type}: {attr.value}
            </li>
          ))}
        </ul>
      </div>
    ))}
  </div>
);

useTokenDataContract

Interact with the token data contract abi

const tokenId = 420;
const tokenDataContract = useTokenDataContract();
const tokenUri = await tokenDataContract.getTokenURI(tokenId);
const tokenData = await fetch(tokenUri).then(r => r.json()));

useTotalSupply

Get the total tokens minted in your collection. Here's a popular example of how you might display how many tokens are left to mint during a drop.

const { config } = useNameless();
const { data: totalSupply, loading } = useTotalSupply();

return (
  <div>
    {totalSupply?.toString()} / {config?.collection.maxTokensPerDrop}
  </div>
);

Helper Methods

getTokenIdsFromPurchaseReceipt

Provide this function with a ContractReceipt and it will give you the token ids from any transfer events.