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

@7i7o/tokengate

v1.0.2

Published

ERC721 Non-Transferable implementation for Token Gating

Downloads

27

Readme

ERC721TGNT (NFTs for Token Gating, Non-Transferable)

ERC721 Non-Transferable Implementation, focused on saving gas for Token Gating

Using owner Address as TokenId

The intent of this implementation is to save as much gas as possible by trimming down on storage and evm instructions from the stardard implementations (being OpenZeppelin's the most widely used).

The use of common implementations depend on storing data for owner, id, approved and (multiple) approvedForAll, and using this for common tokenGating wastes a lot of gas on deploying contracts and more importantly minting, which wastes users gas.

Since the objective of token gating is allowing access of an address by checking a token ownership, several use cases don't need this access being exchanged on secondary markets. By removing these transfers, there's no need for approvals or aperators, allowing us to improve gas use on the smart contract thus making deployment, minting and burning far more efficient.

This implementation aims to provide a way for users and developers to take advantage of this and saving gas by inheriting it.

This project was developed using the Foundry smart contract development toolchain.

Installing

npm

If you use npm, you can install by running:

npm i @7i7o/tokengate

Foundry

If you are using Foundry (or Forge)just run:

forge install 7i7o/TokenGate

and add a line in your remappings.txt file (it should sit on your main project folder) with:

@7i7o/tokengate=lib/TokenGate/

Usage

Now you can import it in your solidity files like this:

import "@7i7o/tokengate/src/ERC721TGNT.sol";

To inherit this, you need to implement the contructor on your contract and pass a Name and a Symbol for your NFTs, like this:

contract Contract is ERC721TGNT {

    constructor() ERC721TGNT("Name", "Symbol") {}

}

Dev Instructions

To tinker with the implementation, you only need to fork this repo and start hacking.

To build (compile) you can run:

forge build

to build, run:

forge test

Gas Comparison

To have a estimate of gas savings for users and deployers, i ran basic tests deploying a basic contract that inherited OpenZeppelin's ERC721 and another set that inherited ERC721TGNT, both exposing basic _safeMint functionality.

I ran one test for creating a new contract, and another to create the contract and mint 1 token (to measure only minting gas).

The results of gas spent in each test for each contract can be seen in the table below

| Function | TGNT | OpenZeppelin | % Gas Saved by TGNT | | ------------- |--------------:| -------------:|---------------------:| | deploy | 649500 | 1168364 | 44.41% | | safeMint | 26930 | 49462 | 45.55% |

That's roughly 45% gas saving on both deploy and mint.


MIT License

Copyright (c) 2022 7i7o