Day 6 of Building an Equipment System with Smart Contracts (Solidity)

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@therealwolf·
0.000 HBD
Day 6 of Building an Equipment System with Smart Contracts (Solidity)
Day 6 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:

Once again, I found the bug I was hunting yesterday first thing in the morning. 🎯

Turns out, for EIP-712 signature signing, the full typehash needs to be defined for nested structs. A small but annoying issue to deal with, but it’s now working.

```
Nested Structure: Item > Metadata > Stat[]

Typehash before: keccak256("MintWithSignature(....)");
Typehash after: keccak256("MintWithSignature(....)ItemMetadata(....)ItemStat(...)");
```

With that fixed, I was finally able to mint the first Ethgard Legends ERC721 items on testnet - a one-hand sword and a shield. ⚔️🛡️

https://sepolia.explorer.b3.fun/tx/0xaeea0cf533334240c9b30c20c99aa5bf087192dfb7e084cc7fb990de289eb6c5?tab=index

Took the opportunity to improve the EVM indexer tables and overall code related to the items to make sure minting and metadata updates are tracked properly and stored in optimal format. I really enjoy iterating like this - writing code based on actually using it, rather than stressing over getting it perfect on the first go.

After that, I switched back to the frontend. Removed hardcoded items and started displaying live items instead. This required some backend work (API controllers, etc.), but I’ll skip over that for now.

To test equipping, I began implementing the drag & drop mechanism into equipment slots. One small blocker I had was figuring out how to handle drag-n-drop logic in Vue. I decided to go with `vue3-dnd`, which took a bit of learning, but it’s now working smoothly. Slot validation is in place too - so dropping a sword into anything other than the main-hand or off-hand slot won't work. The logic to update the local equipment which is then used to broadcast the changes onchain is not implemented yet, but will be worked on next.

Checkout the video of the current version below:

https://x.com/i/status/1906110141411508543

---

### Today's lesson:

Don’t rely too much on AI. Keep on thinking! 🧠

I often use AI in my coding workflow, mainly for speed & efficiency reasons, but here’s a good example of why  thinking for yourself is still superior.

It hallucinated around the typehash encoding issue. I used GPT-4o to help debug and sanity check, but it kept pointing me in the wrong direction or claimed the code should work when it clearly didn’t. I knew that something had to be up with the encoding, so I went the old-school route - digging through GitHub issues and StackOverflow threads. That’s where I found the fix.

Afterward, I told the AI where the problem was (nested structs), and with more focused prompts, it finally came to the right conclusion.

---

_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 👍._
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,