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

@hempworks/nftmaker

v2.3.0

Published

configuration-based NFT image generator

Downloads

19

Readme

NFT Maker

This package generates images and JSON files for use with the Metaplex Candy Machine. It will take a folder of traits, randomly generate images based on weighting, and create the necessary JSON file with project information, royalty settings, and everything else needed to launch your NFT.

Metaplex offers a similar generator in their CLI, but this package offers a few unique features not currently implemented:

  • The ability to generate one-off, completely-custom images and have them included in the final output.
  • The ability to define trait layers but have them excluded from the final JSON metadata. This is good for layers that are not unique between individual NFTs.
  • The ability to have traits which are not visible and only included in the metadata.
  • The ability to define incompatible layers (e.g. This type of mouth doesn't work with this beard).

Quickstart

# Create a folder for the project
mkdir my-project

# Move your traits folder into your project folder
cp path-to-traits my-project

# Generate a configuration file based on 
# the contents of the traits folder
nftmaker init

# Modify the configuration to specify the edition size,
# project details, uniques, along with any exclusions, and 
# incompatibilities. Then, run the generator:
nftmaker run

Installation

You can install NFT Maker using your favorite Node package manager:

# NPM
npm install -g nftmaker

# Yarn
yarn global install nftmaker

Running NFT Maker

After installation and configuration, you can generate your images and metadata by using the run command inside your project folder:

nftmaker run

This will generate several files:

  • manifest.json An image manifest with every token and attribute
  • stats.json Counts of each attribute and the number of times they are used
  • assets A folder of images and JSON files generated from your configuration file. These files are zero-indexed, meaning that Token #1's filenames are 0.png and 0.json

The contents of the assets folder is what is used to generate your Candy Machine with Metaplex.

Configuration

Required Configuration Values

In addition to the image attributes (traits), there are other configuration options you need to specify so the output JSON is correct. These include the edition size, the project name and description, the creator addresses and shares, and other metadata:

module.exports = {
  editionSize: 10, // How many NFTs should be generated
  maxAttempts: 400, // The maximum amount of times NFT Maker should attempt to find a unique image before failing
  name: 'Solana Project Name', // The name of your project
  description: 'Your description goes here',
  collection: {
    name: 'Solana Project Name (1st Edition)',
    family: 'Solana Project Name',
  },
  size: {
    height: 2000,
    width: 2000,
  },
  sellerFeeBasisPoints: 500,
  creators: [
    {
      address: 'YOUR_ADDRESS_HERE',
      share: 100,
    }
  ],
}

Generating a configuration file from a folder of traits

NFT Maker uses a configuration file to generate the image assets and JSON metadata. NFT Maker can generate this file for you automatically by reading the directory structure of your traits folder.

For example, if you have a folder of layers (traits) like this:

- traits
  - Background
    - Brick.png
    - Blue Sky.png
    - Outer Space.png
  - Hair
    - Crazy Hair.png
    - Normal Hair.png
    - Bald.png
  - Eyes
    - Blue Eyes.png
    - Brown Eyes.png
    - Green Eyes.png
  - Face
    - Face.png

NFT Maker can read this folder and generate an example configuration for you. You are free to further customize this configuration file to your liking.

If you've already generated a config file and need to overwrite your changes, you can pass --force to overwrite the existing file:

nftmaker init --force

Ordering your traits

Your project's traits are probably required to be in a certain order to make sense. You can adjust the order of the layers, by filling in the order array inside your configuration:

module.exports = {
  //...
  order: ['Background', 'Face', 'Eyes', 'Hair'],
  //...
}

Specifying incompatibilities

Some individual trait items may not be compatible visually with another trait item. For example, you may have a "Mouth" item that doesn't work with a certain "Beard" item. You can configure which items are incompatible with each by using the conflicts key, which takes a closure that returns whether the individual trait is conflicting:

module.exports = {
//...
  traits: [
    {
      name: 'Beard',
      items: [
        {
          name: 'Soul Patch', weight: 10,
          conflicts: (traitName, traitValue) => ['Derp',
            'Toothy Grin'].includes(traitValue),
        },
      ],
    },
    {
      name: 'Mouth',
      items: [
        { name: 'Derp', weight: 10 },
        { name: 'Toothy Grin', weight: 10 },
      ],
    }
  ]
}

Excluding traits from JSON output

Some traits may be common to all of your NFTs but do not need to be in the JSON metadata. For example, you may have an outline that needs to be applied to each image. In that case, you can specify an options key to the trait to mark it as excluded:

module.exports = {
  //...
  traits: [
    {
      name: 'Outline',
      items: [
        //...
      ],
      options: {
        excluded: true
      }
    }
  ]
  //...
}

Metadata Only Traits

Some traits are not represented in your images visually but should still be included in the JSON metadata. For example, your project may have traits with a specific "gender", or "favorite rapper". You can specify a trait as metadataOnly to prevent NFT Maker from trying to find a layer for it, but still include the attribute in the output.

module.exports = {
  //...
  traits: [
    {
      name: 'Gender',
      items: [
        { name: 'Male', weight: 5, },
        { name: 'Female', weight: 5, },
        { name: 'Non-binary', weight: 5 },
        { name: 'Other', weight: 5 },
      ],
      options: {
        metadataOnly: true,
      },
    },
  ],
  //...
}

Generating Unique 1/1 Images (Uniques)

Every project tends to need some special, 1/1, ultra-rare images. You can have NFT Maker generate these "uniques" and include them in a random position in your drop. Just specify the specific attributes and their special values in the uniques key of your configuration:

module.exports = {
  //...
  uniques: [
    {
      Background: { name: 'Midnight' },
      Face: { name: 'Iridescent' },
      Eyes: { name: 'Laser' },
      Hair: { name: 'Lightning' },
    },
  ],
  //...
}