bitcoin-nfts / bitcoin-colors

A sample NFT collection that shows the strong connection between Stacks and Bitcoin.
6 stars 2 forks source link

Generation Scripts #29

Closed Jamil closed 1 year ago

Jamil commented 1 year ago

Example use

Generating traits from an address (we hash the address, so any string should be supported — it is not restricted to a specific format):

$ python generate_traits.py bc1qkgqca9l0u02m8x6u5pp7c7ded53z4fjdq66hw5
[
  {
    "trait_type": "Color 1",
    "value": "Green"
  },
  {
    "trait_type": "Color 2",
    "value": "Blue"
  },
  {
    "trait_type": "Color 3",
    "value": "Blue"
  },
  {
    "trait_type": "Color 4",
    "value": "Maroon"
  }
]

Specification file example:

[
  {
    "trait_type": "Color 1",
    "value": "Blue",
    "weight": 0.2
  },
  {
    "trait_type": "Color 1",
    "value": "Red",
    "weight": 0.5
  },
  {
    "trait_type": "Color 1",
    "value": "Green",
    "weight": 0.3
  },

  {
    "trait_type": "Color 2",
    "value": "Blue",
    "weight": 0.1
  },
  {
    "trait_type": "Color 2",
    "value": "Red",
    "weight": 0.1
  },
  {
    "trait_type": "Color 2",
    "value": "Green",
    "weight": 0.8
  },

  {
    "trait_type": "Color 3",
    "value": "Blue",
    "weight": 0.6
  },
  {
    "trait_type": "Color 3",
    "value": "Red",
    "weight": 0.2
  },
  {
    "trait_type": "Color 3",
    "value": "Green",
    "weight": 0.2
  },

  {
    "trait_type": "Color 4",
    "value": "Maroon",
    "weight": 0.7
  },
  {
    "trait_type": "Color 4",
    "value": "Turquoise",
    "weight": 0.1
  },
  {
    "trait_type": "Color 4",
    "value": "Chartreuse",
    "weight": 0.2
  }
]

Running a test to ensure actual/expected trait distributions line up, with a sample of 9,000 addresses:

$ python generate_traits.py test
   trait_type       value  expected    actual
0     Color 1        Blue       0.2  0.200889
1     Color 1         Red       0.5  0.498222
2     Color 1       Green       0.3  0.300889
3     Color 2        Blue       0.1  0.098667
4     Color 2         Red       0.1  0.104889
5     Color 2       Green       0.8  0.796444
6     Color 3        Blue       0.6  0.597556
7     Color 3         Red       0.2  0.197444
8     Color 3       Green       0.2  0.205000
9     Color 4      Maroon       0.7  0.700000
10    Color 4   Turquoise       0.1  0.100556
11    Color 4  Chartreuse       0.2  0.199444