create account

Day 1 of Building an Equipment System with Smart Contracts (Solidity) by therealwolf

View this thread on: hive.blogpeakd.comecency.com
· @therealwolf · (edited)
$11.24
Day 1 of Building an Equipment System with Smart Contracts (Solidity)
Day 1 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 items (ERC1155/ERC721) to be equippable on ERC721 tokens (i.e., Heroes).

---

### Today's progress:

Started designing the logic and data structure for the new contract and named it InventorySystem. Had to figure out the category for the items and the available slots, i.e., Main Hand, Off Hand, Head, Shoulder, Chest, Fingers, etc.

Continued developing the code for equipping/unequipping items and initially chose the existing ERC1155 contract for the new items (Weapons, Armor, Accessories).

After writing the tests and having a working first version, I realized that the items needed to be ERC721 instead - allowing for different stats, enchantments, durabilities, and more per item.

This led me to create another ERC721 contract, ItemSystem, along with new data structures for these ERC721-based game items. The items can so far be Weapons, Armor, or Accessories. The base code has been written, including the logic for minting these items (via Signature).

Existing test logic will need to be refactored a bit due to the items now being ERC721 instead of ERC1155.

![image.png](https://files.peakd.com/file/peakd-hive/therealwolf/23tRzWNoQQZR5nAt3TEk9twPS1uq5vfanGd3wboyM8AvXL9zVnshSARg5rjdSTYyETvYP.png)


---

### Todays lesson:

When developing smart contracts, it's critical to find a good balance between designing for future use cases and keeping it simple.

In this case, I decided against making the contract highly generic, as it would create unnecessary complexity and overhead. Instead, I focused on the three main ERC721 items: Weapons, Armor, and Accessories.

Another lesson is that it's better to refactor existing code if the design pattern could be improved - even if the tests are already written and working. Once the contract is live, even with upgradeability, modifying anything related to storage is either impossible, risky or requires migration.

So, better to think twice while still keeping it simple.

---

_PS: If you're having difficulties understanding certain parts but would like to learn more, try the AI feature on peakd or chatgpt/grok to have it explained 👍._
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 98 others
properties (23)
authortherealwolf
permlinkbuilding-in-public-day-1-of-a-smart-contract-based-inventory-system
categorybuildinginpublic
json_metadata"{"app":"peakd/2025.3.5","description":"Starting with some passing tests. Green is good!","format":"markdown","image":["https://files.peakd.com/file/peakd-hive/therealwolf/23tRzWNoQQZR5nAt3TEk9twPS1uq5vfanGd3wboyM8AvXL9zVnshSARg5rjdSTYyETvYP.png"],"tags":["buildinginpublic","ethgardlegends","evm","smartcontracts"],"users":["ethgardlegends."]}"
created2025-03-24 22:46:30
last_update2025-03-29 22:29:27
depth0
children0
last_payout2025-03-31 22:46:30
cashout_time1969-12-31 23:59:59
total_payout_value5.627 HBD
curator_payout_value5.608 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,349
author_reputation581,693,011,827,252
root_title"Day 1 of Building an Equipment System with Smart Contracts (Solidity)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id141,657,541
net_rshares33,001,598,680,082
author_curate_reward""
vote details (162)