Giter Site home page Giter Site logo

infinitywarg / smart-token-id Goto Github PK

View Code? Open in Web Editor NEW
5.0 0.0 0.0 403 KB

Solidity library to encode token metadata into token id. Can be used with ERC721 and ERC1155 tokens for encoding NFT metadata upto 256-bits.

License: MIT License

JavaScript 50.37% Solidity 49.63%

smart-token-id's Introduction

Smart NFT

Smart Token Ids


๐Ÿ’ก Solidity library to encode token metadata into token id. Can be used with ERC721 and ERC1155 tokens for encoding NFT metadata upto 256-bits. ๐Ÿ’ก

What is a Smart Token Id?

ERC721 and ERC1155 tokenization standards have the concept of token id which uniquely defines a particular token type, such that single or multiple supply of each token id can be minted.

Although the metadata of a token id is kept offchain (mostly using IPFS) in many use cases, there's a requirement to have some metadata #onchain.

Examples:

  • Collectibles NFT DNA
  • Parameters for Ggenerative Art
  • Attributes of a financial instrument
  • And many others...

This on-chain metadata can be maintained in the token contract's state variables using structs and mappings. However, such implementation requires that any frontend/backend which may need that metadata, or another contract which may build transactions using that metadata, must query the token contract each time.

Solidity has 256-bit unsigned integers as token ids. What if we encode on-chain metadata into the token id itself, so that it can be destructured anytime, anywhere?

These are two reference implementations of such 'Smart Token Ids' using bitwise operators.

Reference Implementations

In both implementations, developers are expected to know the metadata before encoding it into a token id.

  • Solid Token Id: Metadata is defined in a struct such that total bit lengths of all struct members sum to 256-bits. Solidity packs the entire struct into a single storage slot.
  • Liquid Token Id: Metadata is passed as an array of uint256 with a corresponding array of bit lengths such that they sum to 256-bits.

If the sum is less than 256 bits, please prefix another data with remaining bits and value 0.

Difference between the two implementations is that Solid Token Ids cannot be changed once developed and deployed, while Liquid Token Ids are relatively malleable and can be changed by changing input arrays.

Each implementation has two functions:

  • id() encodes a Smart Token Id from input struct or array containing metadata
  • metadata() decodes a Smart TokenId into struct or array containing metadata

Next enhancement is removing the exact 256-bit sum requirement.

smart-token-id's People

Contributors

infinitywarg avatar

Stargazers

Likem avatar Akshit Choudhary avatar afrideva avatar Kavita B avatar Prabuddh Kumar Ashok avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.