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

erc721b

v0.2.1

Published

An improvement on the [ERC721A](https://github.com/chiru-labs/ERC721A) implementation. [Read more](https://www.badbabybearbots.com/erc721b.html).

Downloads

7

Readme

ERC721B

An improvement on the ERC721A implementation. Read more.

ERC721B is a stripped down version of ERC721. No bells, no whistles. Some key considerations are the following.

  • Primary designed for cheaply mass minting by a special token id incrementer. If batch minting is not a concern, you might want to still use ERC721.
  • tokenURI() in ERC721 cannot be used in all cases. It was added to satisfy the IERC721Metadata interface. We moved this requirement to presets/ERC721BPresetStandard.sol instead.
  • name() is stored though usually never changes. returning a name() pure is more efficient. It was added to ERC721 in order to
    satisfy the IERC721Metadata interface. We moved this requirement to extensions/ERC721BMetadata.sol instead.
  • symbol() is stored though usually never changes. returning a symbol() pure is more efficient. It was added to ERC721 in order to
    satisfy the IERC721Metadata interface. We moved this requirement to extensions/ERC721BMetadata.sol instead.

1. Install

$ npm i --save-dev erc721b

2. Usage

A basic example on how to inherit the ERC721B in your contract would look like the following. This example uses ERC721BBaseTokenURI to generate a dynamic URI in tokenURI

import "@openzeppelin/contracts/access/Ownable.sol";
import "erc721b/contracts/extensions/ERC721BBaseTokenURI.sol";

contract MyCollection is Ownable, ERC721BBaseTokenURI
{
  function mint(address to, uint256 quantity) external onlyOwner {
    _safeMint(to, quantity);
  }

  function name() external view returns(string memory) {
    return "My Collection";
  }

  function symbol() external view returns(string memory) {
    return "MYC";
  }

  function supportsInterface(bytes4 interfaceId) 
    public view virtual override(ERC721B, IERC165) returns(bool) 
  {
    return interfaceId == type(IERC721Metadata).interfaceId
      || super.supportsInterface(interfaceId);
  }
}

If you would like to manually assign a token's URI you could use the following example.

import "@openzeppelin/contracts/access/Ownable.sol";
import "erc721b/contracts/extensions/ERC721BStaticTokenURI.sol";

contract MyCollection is Ownable, ERC721BBaseTokenURI
{
  function mint(address to, uint256 quantity) external onlyOwner {
    _safeMint(to, quantity);
  }

  function name() external view returns(string memory) {
    return "My Collection";
  }

  function symbol() external view returns(string memory) {
    return "MYC";
  }

  function setTokenURI(uint256 tokenId, string memory uri) external onlyOwner {
    _setTokenURI(tokenId, uri);
  }

  function supportsInterface(bytes4 interfaceId) 
    public view virtual override(ERC721B, IERC165) returns(bool) 
  {
    return interfaceId == type(IERC721Metadata).interfaceId
      || super.supportsInterface(interfaceId);
  }
}

See presets for more examples.

3. Extensions

This library comes with the following extensions.

3A. ERC721BBaseTokenURI

Use this extension if you want token URIs to be determined with a base URI. You need to manually call _setBaseURI(string memory) in your constructor or in another function.

3B. ERC721BBurnable

Use this extension if you want your tokens to be burnable. By default it is not.

3C. ERC721BContractURIStorage

Use this extension if you want your contract have an associated URI. Marketplaces like OpenSea accept this. You need to manually call _setContractURI(string memory) in your constructor or in another function.

3D. ERC721BPausable

Use this extension if you want manually pause minting and transferring. You need to manually call _pause() and _unpause() in another function.

3E. ERC721BSignedTransfer

Use this extension if you want want a cheaper way to approve transfers. signedTransferFrom() is similar to safeTransferFrom() except it accepts a signed message from the owner as authorization.

3F. ERC721BStaticTokenURI

Use this extension if you want to assign static URIs to a token.

3G. ERC721Metadata

Use this extension if you want to assign store the name and symbol in your contract. We separated this out because it's cheaper to use a pure function like function name() pure view returns(string memory).

4. Auditing

Clone this repo in terminal and cd to that folder. Run the following commands.

$ cp .env.sample to .env
$ npm install

Sign up to CoinmarketCap and generate an API key. In .env to set the BLOCKCHAIN_CMC_KEY to your API key.

5. Testing

Make sure in .env to set the BLOCKCHAIN_NETWORK to hardhat.

$ npm test

6. Reports

We've measured the gas costs and prices for minting, comparing OpenZeppelin's ERC721 vs ERC721A vs ERC721B. In our measurements, the same application-level logic is used.

The following example is an example cost conversion from the gas above in USD ($3,000/eth).

The following is an example gas report from the tests ran in this project and could change based on the cost of ETH itself.