npm packages for creator smart contracts

Today we help standardize the metadata for music NFTs. Catalog is a dope music NFT company that released a music metadata standard. Today, we’ll extend that standard by putting 100% of the metadata on-chain as a Base64 encoded JSON string. I will teach you how to publish public NPM packages for your solidity smart contracts. The principles I’ll be following here:

  1. 👁 💛 💿 - built with creators in mind.

  2. 100% open-source code.

  3. MIT license - cc0 technology.

I made a goal to publish a package for music NFT metadata (on-chain).

https://twitter.com/sweetman_eth/status/1552786690149961728?s=20&t=8v_MRPBJtOYYo3DOirItnQ

Here’s the steps I followed:

  1. create Github repo.

  2. npm init.

  3. npm login.

  4. npm publish.

  5. Import the package into your new music NFTs. 🥳

Create Github Repo

To create a Github repo head over to your repositories on Github and create a new repository.

Some details I like to include in my repos:

  • MIT license - cc0 philosophy. Anyone can use this code.

  • Public - cc0 philosophy. Anyone can clone this code.

Once your Github repo is created, open a terminal and clone your project locally with

git clone <your-repo-url>
cloning your github repository

npm init

Now that we’ve created our Github repo let’s initialize the npm package. This is the first time I’ve ever initialized an npm package so forgiv me if these instructions are unclear: I’m still learning myself.

I’m going to use hardhat as the base deployment method for this project so I’ll set up the base contracts structure with npx hardhat init.

npx hardhat init

After setting up my base contract to be included in my NPM package (contracts/)nChainMusicMetadata.sol) I initialize the npm package with

npm init
npm init

Publish the NPM Package

It’s typically recommended to test your packages before deploying but my goal is to ship this as fast as possible & iterate with tests later.

  1. npm login - logs you in to the NPM package management system.

  2. npm publish --access=public - publishes your package publicly for others to use.

npm login

running npm publish --access=public published my npm package successfully!

You can view the NPM package I published here.

my first public npm package

Import your Package

Now I want to test to make sure the package works. To test, I’ll spin up a separate hardhat repo (following the steps I listed in the “npm init” section). Once I create the new repo, I’ll try installing the package I just created with

npm i onchain-music-metadata

Here’s how it looks to inherit my OnChain Music Metadata contract:

  • contract MyMusic is OnChainMusicMetadata

the MyMusic contract now has OnChainMusicMetadata

Support

I am an independent smart contract engineer. I have a few different options for you to support me as a creator:

  • 0.0001 ETH - This article is an NFT. It would really help if you collected this NFT to support my writing of future articles. ✏️

  • Free - follow me on Twitter here. 💬

  • Free - share this article to help propagate the meme. 🦠

  • more coming soon. 🌛

Loading...
highlight
Collect this post to permanently own it.
sweetman logo
Subscribe to sweetman and never miss a post.