Day 8 of "Building an Equipment System with Smart Contracts" for @ethgardlegends.
Imagine you find a cool sword and want to equip it to your hero to gain benefits in the game. That's what I'm building.
In technical terms, the goal is to allow NFTs (ERC1155/ERC721) to be equippable on other NFTs (ERC721 => Heroes).
Today's progress:
Started the day by giving both the Equipment and ERC721 Items smart contracts a bit of polish and deploying new versions. They should be production-ready at this point.
Next up: looked into adding stats for ERC1155 items. In this case, I wanted to introduce a LUCK
stat to skins, which would increase the rewards earned in battle.
Unlike ERC721s, which have unique metadata per token, ERC1155s are semi-fungible — so stats need to be stored within the blueprint, not per individual NFT.
You could store this offchain, of course, but since the goal is to have as much logic via smart contracts as possible, it’s all being stored directly onchain.
Since skins and other ERC721/ERC1155 items exist in multiple rarities (and potentially levels), I needed a system that could scale. That meant figuring out a fair and flexible stat budget per item. I did quite a bit of research for this part. The current system isn’t finalized yet, but for LUCK
specifically, I decided to store it as a value between 1 and 10000 - essentially simulating a float where 10000 = 100.00%
and 1 = 0.01%
and having a multiplier of 1.5 to 1.7 between rarities.
After updating the indexer and backend infrastructure to support this, I switched over to the frontend and started designing the initial version of the stats overview per hero.
If you’re wondering why the hero isn’t holding a sword or shield - it’s simply because I haven’t minted those yet on the new version of the contract.
Today's lesson:
Research, baby.
When building smart contracts, it’s worth taking the time to plan ahead. Not everything has to be used from day one - but doing the research and designing systems that are general enough can save you from painful migrations later on.
PS: If you're having trouble understanding certain parts but want to learn more, try the AI feature on Peakd or ChatGPT/Grok to have it explained 👍.