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

micro-onchain-metadata-utils

v0.1.1

Published

On-chain JSON builder in solidity

Downloads

18

Readme

µ on-chain metadata utils

Features:

  1. on-chain base-64 encoding for any content type
  2. on-chain json builder (supports arrays, nested content).
  3. re-exports openzeppelin strings support

this is the spiritual successor of https://github.com/ourzora/nft-editions/blob/main/contracts/IPublicSharedMetadata.sol the public shared metadata renderer libraries within nft-editions.

This project may be exported and deployed on-chain as a registry, but for now is being offered in library form.

API:

  1. MetadataBuilder: Main class for metadata methods
    1. generateJSON(MetadataBuilder.JSONItem[] items): Takes a list of items and makes a key value json object from them. Objects with empty values will be removed.
    2. generateEncodedJSON(MetadataBuilder.JSONItem[] items): Same as above but returns a data-uri instead of the raw JSON string.
    3. generateSVG(string contents, string viewBox, string width, string height): Generates a SVG tag and content for an SVG image.
    4. generateEncodedSVG(string contents, string viewBox, string width, string height): Same as above but generates a data-uri instead of the raw SVG.
    5. generateJSONArray(MetadataBuilder.JSONItem[] itemsArray): Takes an array of items and using the value and quote flags generates a JSON array. Ignores the key value of the object and empty values will be removed from the array generated.
    6. encodeURI(string contentType, string content): Encodes the given content string as a base-64 data-uri with the given contentType.
  2. MetadataMIMETypes: List of common metadata mime type constants
    1. mimeJSON = "application/json"
    2. mimeSVG = "image/svg+xml"
    3. mimeTextPlain = "text/plain"
  3. MetadataJSONKeys: List of common NFT Metadata JSON keys
    1. keyName = "name"
    2. keyDescription = "description"
    3. keyImage = "image"
    4. keyAnimationURL = "animation_url"
    5. keyAttributes = "attributes"
    6. keyProperties = "properties";
  • All methods are views returning strings unless otherwise noted.
import {MetadataBuilder} from "micro-onchain-metadata-utils/MetadataBuilder.sol";
import {MetadataJSONKeys} from "micro-onchain-metadata-utils/MetadataJSONKeys.sol";

contract NFTObject {
  function contractURI() external view returns (string memory) {
    // Build JSON object
    MetadataBuilder.JSONItem[] memory items = new MetadataBuilder.JSONItem[](2);
    items[0].key = MetadataJSONKeys.keyName;
    items[0].value = "Contract Name";
    items[0].quote = true;
    items[1].key = MetadataJSONKeys.keyImage;
    // Build Embedded SVG
    items[1].value = MetadataBuilder.generateEncodedSVG({
      contents: "<rect width='10' height='10' style='fill: red' />",
      viewBox: '0 0 10 10',
      width: '10',
      height: '10',
    });
    items[1].quote = true;

    // Build JSON Array
    MetadataBuilder.JSONItem[] memory randomNumbersArray = MetadataBuilder.JSONItem[](2);
    properties[0].value = '2';
    properties[0].quote = false;
    properties[1].value = '42';
    properties[1].quote = false;
    
    items[2].key = 'randomNumbers';
    items[2].quote = false;
    items[2].value = MetadataBuilder.generateJSON(properties);

    return MetadataBuilder.generateEncodedJSON(items);
  }
}