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

@violetprotocol/erc721extendable

v1.2.1

Published

Extendable conversion of the ERC721 token standard

Downloads

6

Readme

ERC721 Token Extendable<>Extensions

ERC721 token standard implementation conversion to be usable by Extendable<>Extension architecture.

Re-use and replace specific components of your ERC721 token contract using extensions. You can easily upgrade and replace specific components and functions, like minting and burning without having to replace the entire contract. Common hooks like _beforeTokenTransfer can also be upgraded where other functions make call outs to it during its lifecycle.

Usage

npm install @violetprotocol/erc721extendable
yarn add @violetprotocol/erc721extendable
import "@violetprotocol/erc721extendable/contracts/extensions/base/ERC721.sol"
import "@violetprotocol/erc721extendable/contracts/extensions/metadata/ERC721Metadata.sol"
import "@violetprotocol/erc721extendable/contracts/extensions/enumerable/ERC721Enumerable.sol"
import "@violetprotocol/erc721extendable/contracts/extensions/ERC721MetadataEnumerable.sol"

contract Token is ERC721 {}
contract MetadataToken is ERC721Metadata {}
contract EnumerableToken is ERC721Enumerable {}
contract MetadataEnumerableToken is ERC721MetadataEnumerable {}

Architecture

There are four top-level Extendable token contracts:

  • ERC721
  • ERC721Metadata
  • ERC721Enumerable
  • ERC721MetadataEnumerable

Note that all token contracts leave the implementation of mint and burn functions to the developer and in this case, they can be added after deployment as separate extensions to extend your token contract with. The Metadata token contracts do have a burn function implementation already that removes metadata upon token burn, but can be inherited and developed upon further prior to extending.

ERC721

This contains the base functionality for the ERC721 contract.

ERC721Metadata

This contains the extension functionality for ERC721 tokens to manage tokenURIs for tokens and to be able to get the token collection name and symbol.

ERC721Enumerable

This contains the extension functionality for ERC721 tokens to be enumerable. This helps track the number of tokens issued, total supply, and the number of tokens owned by an address.

ERC721MetadataEnumerable

This contains a combination of the Metadata and Enumerable functionality.

Extensions

Each top level contract implementation is an Extendable contract extended with numerous extensions that now house the token logic. The functions are separated into extensions that are extended by the main contract during deployment.

ERC721

ApproveLogic.sol - contains all state-mutating functions involving token approvals.

GetterLogic.sol - contains all view-functions for reading state from the contract.

ERC721HooksLogic.sol - contains the _beforeTokenTransfer and _afterTokenTransfer hooks.

OnReceiveLogic.sol - contains the logic for checking token receive by contracts.

TransferLogic.sol - contains the core transfer logic.

Additional

MintLogic.sol - contains the core internal mint logic that should be inherited by an external contract BasicMintLogic.sol - contains a basic implementation of mint logic that inherits MintLogic.sol

BurnLogic.sol - contains the core internal burn logic that should be inherited by an external contract BasicBurnLogic.sol - contains a basic implementation of burn logic that inherits BurnLogic.sol

ERC721Metadata

MetadataGetterLogic - contains all metadata-related view-functions for reading metadata state. SetTokenURILogic - contains the internal _setTokenURI function for setting URIs to tokens. MetadataBurnLogic - contains a metadata-specific implementation of burn logic.

ERC721Enumerable

EnumerableGetterLogic - contains all enumerable-related view-functions for reading enumerable token state. EnumerableHooksLogic - contains an overridden implementation of the _beforeTokenTransfer hook for enumerable tokens.

Storage

ERC721Storage

Records the main ownership state for the ERC721 token:

struct ERC721State {
  // Token name
  string _name;
  // Token symbol
  string _symbol;
  // Mapping from token ID to owner address
  mapping(uint256 => address) _owners;
  // Mapping owner address to token count
  mapping(address => uint256) _balances;
  // Mapping from token ID to approved address
  mapping(uint256 => address) _tokenApprovals;
  // Mapping from owner to operator approvals
  mapping(address => mapping(address => bool)) _operatorApprovals;
}

ERC721TokenURIStorage

Records the additional token URI information for the ERC721 token:

struct TokenURIState {
  // Mapping from token ID to token uri
  mapping(uint256 => string) _tokenURIs;
}

ERC721EnumerableStorage

Records the enumeration state for the ERC721 token:

struct ERC721EnumerableState {
  // Mapping from owner to list of owned token IDs
  mapping(address => mapping(uint256 => uint256)) _ownedTokens;
  // Mapping from token ID to index of the owner tokens list
  mapping(uint256 => uint256) _ownedTokensIndex;
  // Array with all token ids, used for enumeration
  uint256[] _allTokens;
  // Mapping from token id to position in the allTokens array
  mapping(uint256 => uint256) _allTokensIndex;
}

Requirements

nodejs >=12.0

Build

npm install to install all dependencies.

npx hardhat compile to build all contract artifacts.

Test

npx hardhat test to run tests.