I did previous articles on NFTs regarding the concept itself and then how to mint one on Opensea (here and here), what I was missing though is to go through the process of deploying the smart contract itself, hosting the metadata on IPFS and creating the image from scratch. If you take a look on twitter, it appears that all crypto folks are rocking their own NFTs as avatars, I wanted to make something similar while not being rich enough to afford a crypto punk. And I love experimenting.

I chose the ERC-1155 standard as it appears to most advanced one. A couple of interesting characteristics :

  • You can mint NFTs via a function call, in the previous market standard (ERC-721) you basically had to deploy a brand new smart contract for each NFT
  • You can batch mint and batch transfer (efficiency gains)
  • You can mint fungibles and non fungible tokens

For all those reasons, I wanted to have some practical experience with the token standard.

Step 1 : Create your avatar

First step is obviously to create your own avatar. I am not a design guru, I am a simple man, I like paint on windows. Sue me.

So open up paint,

You then have to :

  • Zoom to the max 800%
  • display gridlines (in the view menu)
  • chose the brush and the smallest size possible
  • There you go, every square is a pixel and you can color them

I like astronauts, so I spent 30 minutes doing my own astronaut NFT, I then recalibrated the image to 150 * 150 pxl just to have something bigger and was done with this part.

without resize (cosmo.png) and with resize (cosmo2.png)

Step 2 : Storing the metadata on IPFS

When you mint an NFT with erc-1155 (or 721) you need to specify an URI in the function call, this URI is basically the link to the metadata that will “define” your NFT.

You basically mint a token via the smart contract and the token references this URI that holds the information relative to the token.

So now we have to host our metadata and generate this URI.

First we need to host the image somewhere, I did it simply on my github :

Right click on the image, display image and then simply copy the address :

Then we need to create the metadata, which is a super simple json file :

  • We have an ID
  • We have a name
  • And we have the URL to the image

Alright, now that we have the JSON file ready, time to host it and generate the URI.

You can leverage directly IPFS to host your file and get the precious CID and URI:

In my case, I used nft.storage as my proxy to IPFS as it was really conveniant.

Go on the website, create an account, log and then simply upload a new file :

you have your CID ! Simply click on the link in the CID column, and you will access directly your json file.

Copy and save the URL, in my case : https://bafkreieagy63azbjxgjad5jnrekgqc22lmnhx2gmqgb2pkgzsbkj3s22oe.ipfs.dweb.link/

Step 3 : Deploy smart contract, mint token, transfer the token

Time to hit remix (https://remix.ethereum.org/), on rinkeby of course, mainnet is too expensive right now :

You can create a new smart contract, import the ERC-1155 standard from our friends at OpenZeppelin and then create the contract. I called mine contract_cosmo. Then create a constant cosmo that will define your collection and finally a constructor that will actually mint the NFT.

Copy paste the URI as an argument and call the _mint function with the msg.sender as the receiver, cosmo as the type of the NFT, the number of NFTs (in my case 1) and that’s it.

Then it’s time to compile the contract and then deploy it. I used my personal metamask wallet to deploy it on Rinkeby (injected web3) :

Once your contract is deployed, you’re done. You can even go check on https://testnets.opensea.io/ your new NFT :

As you can see, there is native support on opensea, even on rinkeby ! simply connect your web3 wallet and you should see your NFT appear.

Now if you want to transfer it to another address, easy :

You can use the safe transfer function, simply put your address where you minted your nft (associated with your web3 wallet) in the from section, the target wallet in the to form. the id of your NFT is 0 as specified in your contract : 

uint256 public constant cosmo = 0;

amount specifies how much do you want to transfer (we had only 1) and finally click on transact

I transfered the NFT to another wallet and then imported it in my mobile metamask wallet :

If you don’t see it, simply click on import NFTs, specify the contract number and the token ID, you can find both on etherscan linked to the address that was used to deploy the smart contract :

Congratulations, you have created your own avatar, generated metadata, hosted it on IPFS, deployed an ERC-1155 contract, minted the NFT token based on your metadata and then transfered the token to another wallet !


Brax

Dude in his 30s starting his digital notepad