I went deep on the @lootproject contract and I thought it might be helpful to break it down for Twitter. Presenting "How the Loot Contract Actually Works": A thread.
It starts with 8 categories arranged as 8 arrays, each holding 3-18 unique items. The categories include weapons, chest, head, waist, foot, hand, necklace, and rings. Then there's name prefixes and suffixes, and overall suffixes. 1/
An on-chain generated NFT requires a random number to begin its work, and in this case that is simply your token ID. In order to maximize randomness, that number is expanded for each unique choice by concatenating the token ID and the category to create a new random number. 2/
So basically for tokenID 123 they created 8 strings: WEAPON123, CHEST123, HEAD123 etc, and then converted each of those strings into a new number. 3/
An item is chosen using mod and picking one item out of the array. It divides the random number by the possible category choices and uses the remainder as the chosen item.
So if WEAPON123 becomes 345678 and there are 18 weapon choices, the chosen weapon will be #6. 4/
Once an item is chosen, it is randomly assigned a GREATNESS value on a scale of 0-20.
If greatness > 14, the item gets an "of Power" type of suffix.
If greatness > 18, the item gets an "Agony Glow" type of prefix.
If greatness > 19, the item gets a +1 suffix. 5/
I think greatness is the most interesting part of this contract, but there is no way to access it. Loot came out with a Loot Components contract to access individual component numbers more easily, but they didn't add greatness as a return value. etherscan.io/address/0x3eb4… 6/
I wrote a simple function to return greatness and it works for any Loot derivative as long as you know the string prefix and token ID. I haven't deployed yet, so if someone else wants to give this a try and put it live as a library or something it would be a huge help. 7/
The last thing they did that I really like is build the SVG in the contract. I know other projects have done this before, but this is the first one I've read myself, and it's just lovely.
There's a ton of power here and I can't wait to try other applications of the strategy. 8/
I checked out #bloot and @thenproject_n as well. Bloot didn't make any changes, and the N project took a very similar strategy to original Loot although there's more adding numbers together and less smashing strings together. 9/
And of course, I wouldn't be a nerdy smart contract coder girl if I didn't clone the contract and launch my own Loot derivative. Introducing @purse_project.
A few things I learned from launching my own Loot derivative: 10/
First, that shit was expensive. On a Friday night it cost me $3,625.34 in transaction fees to launch, and my first attempt failed for a penalty fee of $2,612.84. 11/
So it cost me roughly $6,200 to launch a contract for fun and no profit until royalties, which are nowhere close to guaranteed. 12/
Second, my first attempt failed because it's the largest byte-size contract I have yet deployed to mainnet, and I'm using Truffle as my deployer which has a built-in gas limit. I forgot to set the gas limit high enough in my mainnet configs and it ran out. Ouch. 13/
And finally, I wish I'd taken more time to build user experiences against the contract before launching, so I could discover the missing Greatness feature and add more bells and whistles to support actual real world game play. 14/
All that said, it's been such a fun experience and I am so grateful to the nearly 200 people who have minted their free Purse and supported the project. 15/
Of all the NFTs projects I've worked on so far it's the one I feel most personally satisfied about, because it was a mere 14 hours from inception to launch, and that's a crazy fun ride for a coder. 16/
If you like this thread, please feel free to visit purseproject.io to mint your free Purse, and follow @purse_project to stay up-to-date on all the crazy new things I decide to build next.
Thanks for reading!
... 17/
If you want to read more, check out my previous thread reviewing various NFT smart contracts!
Several people asked me yesterday how to read the code for NFT smart contracts, so here's a brief thread on how I do it.
1/ First go to @opensea and find an NFT you want to review and click into its details section. In there you'll find a link to the contract on Etherscan.
2/ Click that link and you'll land on the Contract Overview page. Find the tab that says "Contract", and if it's got a green check mark you can get excited because it means the developers uploaded code for you to read.
I've been reviewing some of the recent NFT smart contracts as I work on my own, and it's awesome to see the evolution from one version to the next and the little innovations each team puts in. Here's a thread of my favorite contract tricks.
1/ First, I reviewed the following NFT projects, listed in order of their contract launch:
- BAYC
- The Alien Boy
- Wicked Craniums
- My Fucking Pickles
- Cool Cats
- Bulls on the Block
- Forgotten Runes Wizard Cult
- Sewer Rat Social Club
- Lucky Manki
- Degenz
2/ I also wanted to review @MadCatMilitia and @DeadHeadsNFT, but they did not upload their source code to Etherscan and unfortunately I don't like to read decompiled byte code. Will revisit them if they update!
So, starting with BAYC, which is my "genesis" contract.