Impluse News
  • Home
  • News
  • Politics
  • Business
  • National
  • Culture
  • Opinion
  • Lifestyle
  • Sports
No Result
View All Result
  • Home
  • News
  • Politics
  • Business
  • National
  • Culture
  • Opinion
  • Lifestyle
  • Sports
No Result
View All Result
Impluse Logo
No Result
View All Result
Home NFT

Step-by-step instructions on how to create an NFT collection on Golang + Ethereum (part 1)

by Impluse News Desk
February 13, 2022
in NFT
0
NFT
7.9k
SHARES
788.7k
VIEWS
Share on FacebookShare on Twitter

After a little research, I was able to break the initial task from the abstract “create an NFT collection” into smaller and more specific ones, namely:

  • c generate 10,000 unique images
  • c generate 10,000 metadata for each image
  • upload 10,000 images along with metadata to decentralized storage
  • create a smart contract for NFT tokens
  • upload the created smart contract to the Ethereum mainnet
  • create a website that will interact with our smart contract using web3, where users themselves will be able to change their ethers to our NFT tokens

It would seem trifles, but no, at each stage, unforeseen moments awaited me, which we will now talk about.

How to generate 10,000 unique images?

Why exactly 10,000? The answer is quite simple, most popular NFT projects offer collections of exactly 10,000 NFT tokens. Each creator is free to decide how many NFT tokens he wants to release, but we decided not to deviate from the canon and also made 10,000 tokens.

So how do you generate 10,000 unique images anyway? Of course, with the help of automatic layering on top of each other. After some thought, the artist and I came to the conclusion that for our project we need the following layers:

  1. background – 20 pcs
  2. character’s torso – 25 pcs
  3. head – 15 pcs
  4. emotions – 20 pcs
  5. clothes – 30 pcs
  6. shoes – 25 pcs
  7. accessories – 40 pcs

In total, we ended up with approximately 175 unique png layers, which is more than enough to get 10,000 unique characters. Now there is nothing left at all, namely to write a utility that will accept blanks in the form of layers at the input, and at the output, it will give ready-made characters. 

I will write to Golang, so let’s go. First, we need to define 2 structures in the domain package, one for the layers and one for the canvas.

package domain

import (
	"image"
	"image/color"
)

// ImageLayer struct.
type ImageLayer struct {
	Image    image.Image
	Priotiry int
	XPos     int
	YPos     int
}

//BgProperty is background property struct.
type BgProperty struct {
	Width   int
	Length  int
	BgColor color.Color
}

Let’s take a closer look at both structures.

ImageLayer:

  • Image – layer image
  • Priority – layer priority, because layers must be applied in a certain order, first the background, then the torso, then the head, etc…
  • XPos, YPos – position of the canvas layer

BgProperty:

  • Width – canvas width
  • Length – canvas length

So, when the basic structures are described, we can move on to writing a service that will actually combine our layers in a certain order. 

The service code is quite simple, at the input the service takes a list of layers and canvas parameters, and at the output, it returns bytes of the generated image. I would like to note that Go has a fairly good library for working with images, and it is with it that we will work, on the actual code:

package combiner
 
import (
   "bytes"
   "image"
   "image/draw"
   "image/png"
   "nft/internal/domain"
   "sort"
)
 
type service struct {
}
 
func NewBasicImageCombiner() domain.ImageCombiner {
   return &service{}
}
 
func (s *service) CombineLayers(layers []*domain.ImageLayer, bgProperty *domain.BgProperty) ([]byte, error) {
 
   // Sort list by position.
   layers = sortByPriotiry(layers)
 
   // Create image's background.
   bgImg := image.NewRGBA(image.Rect(0, 0, bgProperty.Width, bgProperty.Length))
 
   // Set the background color.
   draw.Draw(bgImg, bgImg.Bounds(), &image.Uniform{bgProperty.BgColor}, image.Point{}, draw.Src)
 
   // Looping image layers, higher position -> upper layer.
   for _, img := range layers {
 
       // Set the image offset.
       offset := image.Pt(img.XPos, img.YPos)
 
       // Combine the image.
       draw.Draw(bgImg, img.Image.Bounds().Add(offset), img.Image, image.Point{}, draw.Over)
   }
 
   // Encode image to buffer.
   buff := new(bytes.Buffer)
   if err := png.Encode(buff, bgImg); err != nil {
       return nil, err
   }
 
   return buff.Bytes(), nil
}
 
func sortByPriotiry(list []*domain.ImageLayer) []*domain.ImageLayer {
   sort.Slice(list, func(i, j int) bool {
       return list[i].Priotiry < list[j].Priotiry
   })
   return list
}

Great, when the code for generating images is ready, we can move on to generating metadata.

Tags: create NFTnftnft project

Impluse News Desk

Related Posts

NFT
NFT

NFT pictures will be hacked at The Standoff

February 15, 2022
Analysis of the tasks of the contest for hacking NFT “The Standoff Digital Art”
NFT

Analysis of the tasks of the contest for hacking NFT “The Standoff Digital Art”

February 14, 2022
nft
NFT

Step-by-step instructions on how to create an NFT collection on Golang + Ethereum

February 12, 2022
Next Post
A few words about Solana and ed25519

A few words about Solana and ed25519

Analysis of the tasks of the contest for hacking NFT “The Standoff Digital Art”

Analysis of the tasks of the contest for hacking NFT “The Standoff Digital Art”

Ethereum

Ethereum, smart contracts: you should know

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us

Recommended

Volochkova

“Beated or scratched by a cat?”: Volochkova posted a photo of terrible bruises

5 months ago
Analysis of the tasks of the contest for hacking NFT “The Standoff Digital Art”

Analysis of the tasks of the contest for hacking NFT “The Standoff Digital Art”

5 months ago
Ivan Krasko

Actor Ivan Krasko was given a terrible diagnosis

5 months ago
Where is the world’s crypto stored? Why are people so stupid? -BTC

Where is the world’s crypto stored? Why are people so stupid? -BTC

5 months ago

Instagram

    Please install/update and activate JNews Instagram plugin.

Categories

  • Business
  • Crypto
  • Culture
  • Featured
  • Lifestyle
  • National
  • News
  • NFT
  • Opinion
  • Politics
  • Sports
  • Travel
  • Uncategorized
  • World

Topics

Beijing Beijing Olympics bejing Blockchain crypto Budget 2022 centralization crypto nft corona coronavirus covid covid 19 crypto crypto currency crypto news crypto stored defi blockchain Dmitry game news ice hockey implusenews impluse news Krasnodar moscow Nepryaeva news nft nft and metaverse nft news nft project nft token nft use olympic olympics omicron Poklonskaya Putin \ russia Russian scientist skaters st petersburg ukraine Ukrainian United States Ural dumplings Zakharova
No Result
View All Result

Highlights

कामगारों के लिए ई-श्रम पोर्टल पर रजिस्ट्रेशन की हुई शुरूआत, जानिए कैसे कर सकते हैं रजिस्ट्रेशन

Savor The Cryptocurrency Experience Fully With Crypto Mufasa.

Technology, business, and why freelancers have emerged

Williemgc exceeds 1 million subscribers on YouTube

Cryptocurrency vindication. Arbitrage practice

NFT pictures will be hacked at The Standoff

Trending

Soni Mehta: Acing The World of Dance and Entrepreneurship.
Lifestyle

Soni Mehta: Acing The World of Dance and Entrepreneurship.

by Himanshu Mahawar
May 7, 2022
0

Soni Mehta is a young influencer, professional dancer, choreographer and entrepreneur from Punjab. She has been staying...

ForexGlo

ForexGlo: The young musical artist has shown his A-game through each of his tracks.

April 11, 2022
Shabaz Zamani

Spell bounding millions of listeners around the world with his melodious voice and catchy songs is Shabaz Zamani.

April 6, 2022
कामगारों के लिए ई-श्रम पोर्टल पर रजिस्ट्रेशन की हुई शुरूआत, जानिए कैसे कर सकते हैं रजिस्ट्रेशन

कामगारों के लिए ई-श्रम पोर्टल पर रजिस्ट्रेशन की हुई शुरूआत, जानिए कैसे कर सकते हैं रजिस्ट्रेशन

March 9, 2022
Savor The Cryptocurrency Experience Fully With Crypto Mufasa.

Savor The Cryptocurrency Experience Fully With Crypto Mufasa.

February 28, 2022

Impluse News

Impluse reports news on the latest technology, science, and business developments, their interactions with other industries.

Recent News

  • Soni Mehta: Acing The World of Dance and Entrepreneurship. May 7, 2022
  • ForexGlo: The young musical artist has shown his A-game through each of his tracks. April 11, 2022
  • Spell bounding millions of listeners around the world with his melodious voice and catchy songs is Shabaz Zamani. April 6, 2022

Categories

  • Business
  • Crypto
  • Culture
  • Featured
  • Lifestyle
  • National
  • News
  • NFT
  • Opinion
  • Politics
  • Sports
  • Travel
  • Uncategorized
  • World
  • About Us
  • Contact
  • Privacy Policy
  • Terms and Conditions

© 2022 IMPLUSE NEWS

No Result
View All Result
  • Home
  • Politics
  • News
  • Business
  • Culture
  • National
  • Sports
  • Lifestyle
  • Travel
  • Opinion

© 2022 IMPLUSE NEWS